Get row index (ACF)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

get_row_index() returns the current row index within a have_rows() loop.

Whilst stepping though the rows of a Repeater or Flexible Content field, you may find it necessary to determine the row number (index). This function does exactly that, avoiding the need of a custom $i++ counter.

Rows start at 1 (not 0) [1]

Voorbeeld

while (have_rows('add_code_to_head', 'option')):
   echo(get_row_index());
   print_r(the_row(true));
   echo(get_row_index());
endwhile;

Bronnen