Get row index (ACF): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
 
Regel 2: Regel 2:
  
 
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.
 
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) [https://www.advancedcustomfields.com/resources/update_sub_row/]
  
 
== Voorbeeld ==
 
== Voorbeeld ==

Huidige versie van 29 jul 2022 om 16:02

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