Home › Forums › Add-ons › Repeater Field › Repeater – "while" detect last › Reply To: Repeater – "while" detect last
Treat the repeater field as an array, you can count the number of values.
<?php if( have_rows('services_repeater', $services) ): ?>
<?php $rowCount = count( get_field('services_repeater', $services) ); //GET THE COUNT ?>
<?php $i = 1; ?>
<?php while( have_rows('services_repeater', $services) ): the_row(); ?>
<?php // vars
$service = get_sub_field('service');
$description = get_sub_field('description');
?>
<span class="hint--bottom" data-hint="<?php echo $description; ?>"><?php echo $service; ?></span>
<?php if($i < $rowCount): ?>
<div id="separator"> / </div>
<?php endif; ?>
<?php $i++; ?>
<?php endwhile; ?>
<?php endif; ?>
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.