Home Forums Add-ons Repeater Field Add_row to nested repeater field (child only)


Add_row to nested repeater field (child only)

  • Hi,
    I have nested repeater field.

    • Media
      • Title_1
      • Notes
        • Note_1
        • Publish date
        •  Note_2
        • Publish date
      • Title_2
      • Notes
        • Note_1
        • Publish date
        •  Note_2
        • Publish date

    I can add row like this:

    $row = array(
    ‘Title’ => Title_3,
    ‘Notes’ => array(
    ‘Note’ => ‘My new note’
    add_row(‘Media’, $row);

    I need to add only Note to existing parent Media.

    Please help…

  • Hi @codnictor

    I believe you can use the update_sub_field() function instead. This page should give you more idea about it:

    I hope this helps 🙂

  • Hi @James
    Already I tried this and update_sub_field() function works great when you update an existing field in a row and sub-rows.
    I have to create a new sub-row and fill subfield with some text.

  • Hi @codnictor

    In that case, could you please try to use the field key instead?

    To get the field keys, kindly open the field group editor page and click the “Screen Options” menu. In this menu, please enable the “Field Keys” option for ACF PRO version or set the “Show Field Key” option to “yes” for the free version. I’ve attached a screenshot for your reference.

    If that doesn’t work, could you please try to use the update_field() function?

    Thanks 🙂

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

  • HI WooHoo,
    Yes. I run function add_row in my repeater_field loop.

    In ma case I have:
    Lesson / main repeater
    – Lesson active / subfield true/false
    – Lesson finished / subfield true/false
    – Notes / nested repeater
    — Note – custom sub field
    — Note date – another custom sub field

    I need to create empty Notes row at first page run for each lesson. This is a part of much complicated script. It`s a little complicated to explain 🙂

    if( have_rows('lesson') ): 
        while ( have_rows('lesson') ) : the_row(); 
            // Generate empty rows for each lesson at first run
            // here i have date field which is empty at first start 
            // date is generated at the end 
            if (get_field('start_date') == ''){ 
                    $row = array(
                    	'lesson_date'	=> 1,
                    	'lesson_finished'	=> 0,
                    // add_row('lesson', $row); // this wont work 
                    add_row('field_579eeb638c835', $row); // you must take key of custom field "lesson"
    // fill the field with current date
    if (empty(get_field('start_date'))){
        update_field('start_date', date(Ymd));

    Then I need to add notes to lesson no2 – I have for exaple 5 lessons – 5 main repeater field row.

    //This is a part of ajax call
    $lesson_id = 2; // main repeater field 
    if( have_rows('lesson',$post_id) ): 
        while ( have_rows('lesson',$post_id) ) : the_row();
              if( get_sub_field('notes', $post_id) ){  
                  $notes_row = get_sub_field('notes', $post_id);
              } else {
               $notes_row =  array();
                // Check variables for fallbacks
                if (!isset($input_text) || $input_text == "") { break; }
                array_push($notes_row, array( 'note' => $input_text , 'note_date' => date('d.m.Y') ));
                $notes_row = array( 'notes' => $notes_row );
                update_row('lesson', $lesson_id , $notes_row, $post_id); 
  • 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:

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Add_row to nested repeater field (child only)’ is closed to new replies.