get_row_index()

Overview

This function will return the current loop count within a have_rows() loop.

Change Log

  • Added in version 5.3.4

Parameters

get_row_index()

Return

This function will return the row index starting from 1 (first row = 1, second row =2, etc).

It is possible to change the index starting point so that the first row = 0 using the row_index_offset setting.

Examples

Basic

This example demonstrates how to use this function to output unique ID’s into each row’s wrapper. This is useful for CSS / JS customization.

<?php if( have_rows('slides') ): ?>

	<?php while( have_rows('slides') ): the_row(); ?>

		<div class="accordion" id="accordion-<?php echo get_row_index(); ?>">
			
			<h3><?php the_sub_field('title'); ?></h3>
			
			<?php the_sub_field('text'); ?>

		</div>

	<?php endwhile; ?>

<?php endif; ?>

Related

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.