Support

Account

Home Forums General Issues Updating ACF Repeater that is a CLONE Programtically

Solved

Updating ACF Repeater that is a CLONE Programtically

  • update_field('field_5a846b336d34f', $finalArray , $post_id);
       $finalArray[]=array(
        "field_5a846b336d351"=>"NAME",
        "field_5a846b336d353" => "EMAIL",
        "field_5a846b336d352" => "TITLE",
        "field_5a846b336d354" => "PHONE"
       ); 

    So this is the standard way to add rows to a repeater in ACF. It works great on a repeater that is not nested or in a Flexible content block (ACF). The field id in the update_field is the repeaters, who is inside of a Flexible Content Block. This seems to be giving me fits due to it’s location. I have looked at help docs everywhere. If I am calling the repeater by its field ID, why should it matter where it is located in the layouts in ACF? One more note: This repeater is a CLONE but each time I use it as a clone on the site it has it’s own field ID so that shouldn’t give me grief? I am trying to add multiple rows to it at once. Works great on a repeater NOT buried in ACF objects.

    I don’t know if this will help or not, but it will give you an idea of where the repeater is located in the ACF page build. Below is what I use to get the output:
    while ( have_rows(‘page_builder’,$post_id) ) : the_row();
    if( get_row_layout($post_id) == ‘staff_directory’ ): // Staff Directory
    if( have_rows(‘directory_type’,$post_id) ):
    while ( have_rows(‘directory_type’,$post_id) ) : the_row();
    if( get_row_layout($post_id) == ‘directory_table’ ):
    if( have_rows(‘staff_member’,$post_id) ):
    while ( have_rows(‘staff_member’,$post_id) ) : the_row();
    /// THIS IS WHERE I WOULD CALL THE RESULTS OF THE REPEATING INFORMATION ///
    endwhile;
    endif;
    endif;
    endwhile;
    endif;
    endif;
    endwhile;

  • In order to use update_field() you would need to include all of the rows of the flex field as well as all of the rows of the repeater.

    
    $flex_field = array(
      array(
        // each row of the flex field
        'field_XXXXXXX' => array(
          // nested repeater field
          array (
            // each row of the repeater
            'field_YYYYY' => 'value'
          )
        )
      )
    );
    

    This is not the way to add a row to a repeater nested in a flex field.

    See add_sub_field_row() and/or update_sub_field().

  • https://stackoverflow.com/questions/58914010/insert-repeater-rows-in-flexible-content-programmatically
    Using the information above I was able to get a repeater to work inside a Flexible Content block when it is a single level. As you can tell from my example, I have Flexible Content inside Flexible Content. How would I alter it to make it work another level down?

    $fc_data = array(
            'flexible_content_field_key'          => 'field_5a81b3845b0a3',
            'flexible_content_layout'             => 'directory_table',
            'flexible_content_repeater_field_key' => 'field_5a846b336d34f',
        );
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.