Support

Account

Home Forums Add-ons Repeater Field Update sub field in nested repeater outside of loop

Helping

Update sub field in nested repeater outside of loop

  • I’m having a hard time wrapping my head around the concept of updating sub fields in a multiple nested repeater.

    $total_duration = 0;
        if (has_sub_field('section', $post_id)):
            $parent_i = 0;
            while (has_sub_field('section', $post_id)):
                $parent_i++;
                if (get_sub_field('subsection')):
                    $child_i = 0;
                    while (has_sub_field('subsection')):
                        $child_i++;
    
                        $duration = ex_get_wistia_id(get_sub_field('segment_video_id_wistia'));
                        $duration_time = gmdate("H:i:s", $duration);
                        if (get_sub_field('segment')):
                            $sub_child_i = 0;
                            while (has_sub_field('segment')):
                                $sub_child_i++;
                                $total_duration_time = gmdate("H:i:s", $total_duration);
     update_sub_field( array('section', $parent_i, 'subsection', $child_i, 'segment', $sub_child_i,'start_time'), $total_duration_time );
                                $total_duration = $total_duration + $duration;
                                $total_duration_time = gmdate("H:i:s", $total_duration);
                                $total_duration = strtotime($total_duration_time) + 1;                           
           update_sub_field( array('section', $parent_i, 'subsection', $child_i, 'segment', $sub_child_i,'end_time'), $total_duration_time );
                                var_dump(get_sub_field('notes'));
                            endwhile;
                        endif;
                    endwhile;
                endif;
            endwhile;
        endif;

    I’ved tried update_sub_field( array('section', $parent_i, 'subsection', $child_i, 'segment', $sub_child_i,'notes'), 'It worked!' );

    Where I thought it would work but it didn’t. It’s three layers in with wanting to update the sub_fields for start_time and end_time. They have key values of field_7 and field_8. Any help would be great. I’m doing this on post save so I’m outside ofh the loop and using the post id. I’m looping through the repeaters to grab information from one of the segment_video_id_wistia sub fields as well.

  • Hi @danu4eastudios-com ,

    Thanks for reaching out.

    Kindly have a look at this article should guide you on the same.

    https://www.advancedcustomfields.com/resources/working-with-nested-repeaters/

    Hope this helps 🙂

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

The topic ‘Update sub field in nested repeater outside of loop’ is closed to new replies.