The Repeater field is a really good solution for repeating content like slides, team members, directory, and many more repeating contents.
The Repeater field type acts as a parent to a set of sub fields which can be repeated again and again and there are no limits to the number of repeats either as long as you don’t specify.
The Repeater field will return an array of rows, where each row is an array containing sub field values.
When you add a repeater field, it creates additional functions specifically for looping over rows and accessing sub field values like have_rows, the_row, get_sub_field, and the_sub_field functions.
How to loop through a Repeater field and load a sub field value?
// Check rows exists.
if( have_rows('repeater_field_name') ):
// Loop through rows.
while( have_rows('repeater_field_name') ) : the_row();
// Load sub field value.
$sub_value = get_sub_field('sub_field');
// Do something...
// End loop.
endwhile;
// No value.
else :
// Do something...
endif;
How to loop through a nested Repeater field?
if( have_rows('parent_repeater') ):
while( have_rows('parent_repeater') ) : the_row();
// Get parent value.
$parent_title = get_sub_field('parent_title');
// Loop over sub repeater rows.
if( have_rows('child_repeater') ):
while( have_rows('child_repeater') ) : the_row();
// Get sub value.
$child_title = get_sub_field('child_title');
endwhile;
endif;
endwhile;
endif;
ACF advanced custom loop repeater