Support

Account

Forum Replies Created

  • Hi John,
    I figured out what went wrong in the first place.
    In your solution:

    
    if (get_field('your_field_name') != $last_value) {
            // ourput heading for next section
            // your code here
            
            // set last value to this value
            $last_value = get_field('your_field_name');
          }
    

    you get the data with get_field('your_field_name') from the first item in the database, in my case this was always 3. So it is not the data from the first item in the query. And that’s why I got stucked.
    After some serious thinking and a lot of trial and error I came up with this solution where I use a For loop to get everything organised by label (division):

    
    // Get the values from the ACF object (radio buttons)
    $all_names = get_field_object('medewerker_werkzaam_bij');
    // Put the choices from that object in an array 
    $all_label_names = $all_names['choices'];
    // Count the number of items to use in the 'For' loop. Because a loop starts with '0', decrease the value for that variable with 1				
    $num_labels = count($all_label_names)-1;
    
    for ( $my_label = 0; $my_label <= $num_labels; $my_label++ ){
    	$all_query = new WP_Query(array(
    		'post_type'			=> 'collegas',
    		'posts_per_page'    => -1,
    		'meta_query' 		=> array (
    									'label' 	=> array (
    										'key' 	=> 'medewerker_werkzaam_bij',
    										'value' => $my_label,
    									),
    									'persoon' 	=> array (
    										'key' 	=> 'medewerker_achternaam',
    									),
    								),
    		'orderby'			=> array (
    									'label' 	=> 'ASC',
    									'persoon'	=> 'ASC',
    		)
    	));					
    	if ( $all_query->have_posts() ) {
    	$my_label_name = $all_label_names[$my_label];
    
    	<h2 id="<?php echo $my_label_name; ?>" class="<?php echo $my_label_name;?>"><?php echo $my_label_name;?></h2>
    	<div class="<?php echo $column_class; ?>">
    		while ( $all_query->have_posts() ) {
    			$all_query->the_post();
    			get_template_part( 'loop-templates/content-collegas', get_post_format() );
    		}
    	} else {
    		get_template_part( 'loop-templates/content', 'none' );
    	}
    	</div>
    }
    
    

    This works for me as I wanted it in the first place.
    But thank you for replying and pushing me in the right place

  • Hi John,
    I figured out why it was not working.
    In your suggestion:

    
    if (get_field('your_field_name') != $last_value) {
            // ourput heading for next section
            // your code here
            
            // set last value to this value
            $last_value = get_field('your_field_name');
          }
    

    the data you get from get_field('your_field_name') is the data you get from the first item in the database, not the data from the query. In my case it was always ‘3’.
    I rewrote the entire loop, and now it looks like this:

    
    // Get the values from the radio buttons from the ACF object
    $all_names = get_field_object('medewerker_werkzaam_bij');
    // Get the choices from those radiobuttons and put them in an array
    $all_label_names = $all_names['choices'];
    // Count the number of items in the array to use in the 'For' loop. Because a loop starts with '0', decrease the value in the variable with 1				
    $num_labels = count($all_label_names)-1;
    
    for ( $my_label = 0; $my_label <= $num_labels; $my_label++ ){
    $all_query = new WP_Query(array(
    'post_type'			=> 'collegas',
    'posts_per_page'    => -1,
    'meta_query' 		=> array (
    'label' 	=> array (
    'key' 	=> 'medewerker_werkzaam_bij',
    'value' => $my_label,
    ),
    'persoon' 	=> array (
    'key' 	=> 'medewerker_achternaam',
    ),
    ),
    'orderby'			=> array (
    'label' 	=> 'ASC',
    'persoon'	=> 'ASC',
    )
    ));					
    if ( $all_query->have_posts() ) {
    $my_label_name = $all_label_names[$my_label];
    ?>
    <h2 id="<?php echo $my_label_name; ?>" class="<?php echo $my_label_name;?>"><?php echo $my_label_name;?></h2>
    <div class="<?php echo $column_class; ?>">
    <?php	
    	while ( $all_query->have_posts() ) {
    		$all_query->the_post();
    		get_template_part( 'loop-templates/content-collegas', get_post_format() );
    			}
    		} else {
    			get_template_part( 'loop-templates/content', 'none' );
    		}
    			?></div><?php
    		}
    

    And now I have exactly what I was looking for.
    Thanks for replying and moving me in the right direction.

  • Hi John,

    I’ll have a look at it again and let you know how it worked out.

  • Hi John,

    I’m afraid your solution is not working for me.
    Think I need a ‘foreach’ loop to get this working the way I want.
    This is what I’m looking for:

    
    -- Division Name 1 ---
    Person 1
    Person 2
    Person 3
    
    -- Division Name 2 ---
    Person 1
    Person 2
    
    -- Division Name 3 ---
    Person 1
    Person 2
    Person 3
    Person 4
    Person 5
    
    etc.

    This means that I need to know what value (showing part of the query of my earlier post) is in

    
    'label' 	=> array (
    			'key' 	=> 'medewerker_werkzaam_bij',
    		),
    

    The value should range from 1 to 7. But I really have no idea how to put that value (an ACF field) into a variable so I can check / validate that in a foreach or while loop.

  • Hi John.
    Yes it is in a IF statement like you pointed out.
    But I think I’ve solved it already.
    I did a check if the image and/or video field was not empty, and if so, render it.
    But I also needed to check if the switch with the radiobuttons is present/set.
    So instead of:

    
    $image = get_sub_field('afbeelding');
    $video = get_sub_field('video');
    if ($image) {
    ... do something
    }
    if ($video) {
    ... do something
    }
    

    I now have this one:

    
    $image = get_sub_field('afbeelding');
    $video = get_sub_field('video');
    // This is the radio switch
    $image_or_video = get_sub_field('image_or_video');
    if ($image && $image_or_video == 'Afbeelding') {
    ... do something
    }
    if ($video && $image_or_video == 'Video') {
    ... do something
    }
    

    This solved the front-end rendering issue.
    But apparantly, even if you delete the row with the video, the data is still present.
    And that is strange, because it doesn’t happen when I delete a row with an image.

  • John,

    That’s it! Thank you.
    After I posted this question I realised that all Post data is available in an array, so I was already thinking about some array ‘sniffing’ to get to the correct values.
    But to be honest, I never thought of this one.

    You have been very helpfull, as always.

  • Hi John,

    Thanks for the thorough reply.
    But the thing is, and according to the documentation (and thus the reason why I rely on it), that update_row() should return true or false based on success or failure of the function (https://www.advancedcustomfields.com/resources/update_row/).
    And this used to work!

    After the latest update of ACF Pro, this is not the case anymore.
    I also submitted a support ticket, and I’ll expect a reply after the weekend.

  • Users can change content on the front-end, via a custom form, which will be updated by submitting the form.
    For now, after doing the update_row(), I compare the updated data with the data provided by the user. This works, but involves more code and I’m not happy with it.

  • Thanks @codnictor

    But I gave up!
    I was actually pretty close, but not close enough.
    No matter what I try or do, I just couldn’t get it to work.
    But I have found another solution.

    See my reply at this topic:
    https://support.advancedcustomfields.com/forums/topic/add_row-in-nested-repeater/#post-43614

  • Thanks @acf-support

    But I gave up!
    No matter what I try or do, I just couldn’t get it to work.
    But I have found another solution.

    I removed the nested repeater and made it a normal not nested (stand-alone) repeater.
    The (formerly) parent repeater now has an extra field with a unique number for every row.
    The (formerly) child repeater also has an extra field for every row that corresponds with the unique number of one of the rows in the parent repeater.

    All I have to do now is keep these numbers in sync, which is not that hard.

    And now I can update the (formerly) child repeater with simple instructions like add_row or update_row.

    This might not be the most ideal solution, but it works for me.
    After trying and testing for a couple of days with nested repeaters, I got this solution working in less then an hour. And the results are almost the same.

  • @rinse06

    Did you get a solution?
    And if so, what is it.
    I really like to know, because I’m having difficulties adding a new row in a nested repeater. Seems like nested repeaters are not very well covered by ACF.

  • @codnictor
    Did you manage to get a new row (add_row) at a nested repeater?
    If so, how did you do it.

  • I’ve looked at update_sub_field but that doesn’t help either.
    Isn’t there something like add_sub_row ?

  • @scheurta That didn’t work for me.

    But this one does!
    Just basic PHP manipulating arrays.
    First, create and fill the array:

    while( have_rows('verzoeken') ): the_row();
    $my_data[] = get_row();
    endwhile;

    After that, get the correct field values (you have to use the field keys):

    $row_index = $row_index - 1;
    $date = $my_data[$row_index][field_5791d60e83187];
    $description = $my_data[$row_index][field_5791d60e83188];

    I got the row index in another part of my script from get_row_index(), so I have to subtract that with 1 because the array index starts at 0 and get_row_index() starts at 1.

  • Hi @juiceex and @acf-support,

    Did you find a solution for this?
    Because I’m trying to do something similar with a custom form (no ACF_Form).
    And I just can’t get the image to be saved in the proper field.

    Could you please give more hints (or maybe a code snippet) on how to get uploaded images saved to Field Type: file when not using a ACF_Form?

  • Hi John,
    Good thinking!
    In fact, it is almost the same as putting a generic form (no ACF_FORM) on the front-end with the appropriate fields and store the collected input in the repeater where it belongs.
    Either way, I like this approach.
    Thanks!

  • Haha, problem solved!!!

    It is a pretty complex Field Group I’m working on. And every now and then I make a copy of it, set it to inactive, and keep working on the original one.
    But this leads to confusion when using ACF_FORM because all field-id’s are the same between my original and copied inactive Field Groups.

    It seems like ACF_FORM does not take in account inactive Field Groups.

    So I deleted all my copies, after backing them up, and now I only have 1 Field Group to work with.

    All changes I do now, are immediately reflected in the ACF_FORM.
    And now my ‘Add Row’ button shows ‘Add Talent’.

    Woohoo!

  • John,

    Strange.
    I’ve added another ACF_FORM on the same page, also with a repeater field. And this time that button shows the text I’ve entered in the back-end.
    So my conclusion is that there is no interference with any other plugin or the theme (I use the default Genesis Child theme).
    Maybe when I change the position of the first ACF_FORM on the page.
    (Hmmm, sounds crazy, but I’m going to try it.)
    Nope, didn’t work.
    I’m confused.
    There is no argument like 'addrow_value' => 'Whatever text you want' in the arguments array when calling an act_form($array) is there?

  • Hi James,

    It’s been a while but I finally got the time to look into acf_form(), and I must admit it’s pretty amazing at what you can do with it.
    In fact, I love it!
    The fact that you can even call Field Groups on any page you want to collect data is very powerful.

  • Hi James,
    I gave myself some ‘time-off’ the coming week and will definitely look into this.
    Instead of asking, just learn by doing, so to speak.
    I also came across this tutorial (http://thestizmedia.com/front-end-post-editing-with-acf-pro/) and it looks very promising as it covers some of the things I would like to achieve.
    Can’t wait to get started!

  • James,

    I was kind of busy lately (good for me), so I didn’t had the time to reply to you.
    But to be more specific at my initial question, I’m looking for a way to edit parts of a page/post that is populated with ACF functionality. I don’t intend to create a new post or page, just edit a couple of fields that are, at the time only available on the back-end, to be altered on the front-end.
    These edits must be saved, and the result of it must be reflected on the front-end.
    In other words: a WP Admin has a numerous of fields to fill out in the back-end for a particular page to be shown at the front-end (for clients).
    Some of these fields may never be altered by a client, but must be altered by a WP Admin when things progress.
    Now I want to get this WP Admin kept away from the default WP Dashboard, and do his/her changes on the front-end when logged in successfully.
    So, when a WP Admin has logged in, he gets a ‘Change parameters’ button on the front-end (he never is redirected to the WP Dashboard). Clicking that button must present him/her with some sort of form to alter the fields he only has access to. And after completing an confirming the changes they are saved to WP and reflected to the front-end for the client.
    For example. A Client has requested to buy another 5 items. I want the WP Admin to confirm this on the front-end, so the client sees (on the front-end) he requested for the additional 5 item buy. These items are not bought yet. This is another process following the same principle.

  • Hi Elliot,

    Thanks for joining in. Glad to hear it has your attention.

  • Very nice @solverat !
    But, and this might sound very stupid, where to put this JavaScript.
    The heading says ‘Include this Javascript ONLY in BackEnd.’.
    Can I just put this in my ‘js’ folder of my theme?
    And where and how do I call for this JavaScript in ACF?

Viewing 25 posts - 1 through 25 (of 40 total)