Home › Forums › Add-ons › Repeater Field › Dynamic Repeater Fields with Titles › Reply To: Dynamic Repeater Fields with Titles
Okay I’ve refined it a heap after looking into arrays:
<?php if( have_rows('logos') ):
while( have_rows('logos') ): the_row();
$select = get_sub_field_object('partner');
$value = get_sub_field('partner');
$partnerArray = $select['choices'];
endwhile;
endif; ?>
<?php $colors = $partnerArray;
foreach ($colors as $color) {
global $b;
$b++;
echo "<h3>" . ucfirst($color) . "</h3>";
echo '<div class="row">';
while ( have_rows('logos') ) : the_row();
if(get_sub_field('partner') == "{$color}"):
// display the repeater sub field values
echo '<div class="col-sm-6 col-md-3 text-center py-3" id="'.$b.'">
<a href="' . get_sub_field('website') .'"><img src="' .get_sub_field('logo') . '" /></a>
</div>';
endif;
endwhile;
echo '</div>';
}?>
However it will display the titles regardless. If the titles exist, they are shown, even if there are no items on that page. I need them to only show if there are items.
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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.