Get row index (ACF)

Uit De Vliegende Brigade
Versie door Jeroen Strompf (overleg | bijdragen) op 29 jul 2022 om 16:02
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)
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