Support

Account

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; ?>