Home › Forums › Add-ons › Repeater Field › 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 🙂
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re hard at work on ACF 6.1, and Beta 1 is now available 🚀
— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.