I created a Custom Field with the Repeater layout to add some input text. I would like to display all the values. I found some code on ACF documentation but I can't understand how it works
<?php
$rows = get_field('repeater_field_name');
if($rows)
{
echo '<ul>';
foreach($rows as $row)
{
echo '<li>sub_field_1 = ' . $row['sub_field_1'] . ', sub_field_2 = ' . $row['sub_field_2'] .', etc</li>';
}
echo '</ul>';
}
?>
http://www.advancedcustomfields.com/resources/repeater/
I don't know how much fields I will create with the Repeater and I would like to loop all the values with foreach. Is that possible?
Thank you in advance
Foreach version:
<?php
$rows = get_field('repeater');
if($rows)
{
echo '<ul>';
foreach($rows as $row)
{
echo '<li>sub_field_1 = ' . $row['text'] . '</li>';
}
echo '</ul>';
}
While version:
<?php
// check if the repeater field has rows of data
if( have_rows('repeater') ):
// loop through the rows of data
while ( have_rows('repeater') ) : the_row();
// display a sub field value
the_sub_field('text');
endwhile;
else :
echo 'nothing found';
endif;
?>