Home Forums ACF PRO Get specific row from repeater field


Get specific row from repeater field

  • Hi all,
    I want to retrieve a specific row (I know the index of that row) from a repeater field.
    I’ve searched the forum and the documentation but I can’t find anything that will allow me to do that.
    I tried this one, where $row_index is a number:

    while( have_rows('verzoeken') ): the_row($row_index);
    $date = get_sub_field('datum');
    $description = get_sub_field('omschrijving');

    But, as you might have guessed, that doesn’t work. It returns all data from all rows.
    Is there a ACF way to get the data from a specific row?

  • Hi,

    Try this:

    $row_index = 3;
    $items = get_field( 'verzoeken' );
    if ( $items ) {
    	$date = $items[ $row_index ]['datum'];
    	$description = $items[ $row_index ]['omschrijving'];
  • @scheurta That didn’t work for me.

    But this one does!
    Just basic PHP manipulating arrays.
    First, create and fill the array:

    while( have_rows('verzoeken') ): the_row();
    $my_data[] = get_row();

    After that, get the correct field values (you have to use the field keys):

    $row_index = $row_index - 1;
    $date = $my_data[$row_index][field_5791d60e83187];
    $description = $my_data[$row_index][field_5791d60e83188];

    I got the row index in another part of my script from get_row_index(), so I have to subtract that with 1 because the array index starts at 0 and get_row_index() starts at 1.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.