Home Forums ACF PRO Display data from specific repeater row


Display data from specific repeater row

  • Hey team!

    I am looking for a way to display two things in my WP theme, but it’s getting quite complex and I can’t track down any documentation of doing this.

    I have a repeater field called ‘locations’ setup with 5 subfields (name, phone, street_address, state, postcode). At the moment, I have 2 rows all containing values. EG:

    Name 1
    Phone 1
    Street Address 1, State 1, Postcode 1


    Name 2
    Phone 2
    Street Address 2, State 2, Postcode 2


    I need the ability to split out this information for displaying on different pages. How can I:

    1/ Display all sub fields from a specific row? EG. Show all data from row 2.

    2/ Display a specific sub field from a specific row? EG. Show ‘phone’ from row 2.

    Hopefully someone out there can shed some light on this!

  • There is only one way to do this using acf functions. That is to loop through the repeater and output the row or field that your looking for. This can be done with counters

    if (have_fields('repeater')) {
      $counter = 0;
      while (have_rows('repeater')) {
        // at this point the counter is set to the current row
        // you can output content or not based on that row
        // for example
        if ($row == 4) {
          // output content from row 4

    You can also check values of the fields in the row to see if you want to show that row.

    • Thomas

    • March 16, 2017 at 2:23 am

    You can also go this way

    $rows = get_field('repeater' ); // get all the rows
    $specific_row = $rows[YOUR_ROW_NUMBER]; // 0 will get the first row, remember that the count starts at 0
    $sub_field_value = $specific_row['SUB_FIELD_NAME']; // get the sub field value

    This also explained on the tutorial page for repeaters

  • is there the possibility to show the title of a file repeater field ::.

    So to show the title of the row? Like in an image field.

    with print_r i am getting this: `Array
    [downloads_acf_field_single_product] => Array
    [ID] => 1072
    [id] => 1072
    [title] => Product brochure
    [filename] => M-107-M-111-Alfa-Romeo-8c-DE.pdf`

    So how can i extract the [title]

    • Thomas

    • July 2, 2018 at 10:50 pm

    As simple as this:

    $rows = get_field('repeater' ); // get all the rows
    $specific_row = $rows[YOUR_ROW_NUMBER]; // 0 will get the first row, remember that the count starts at 0
    $title = $specific_row['SUB_FIELD_NAME']['title];

    In your specific example the SUB_FIELD_NAME would be downloads_acf_field_single_product

  • Hello everybody,
    I came across these threads and I am currently trying on the same topic. My repeater sits inside an option page and is queried by within a flexible layout. Unfortunately, it does not work that way, what’s wrong with the code?

    <?php if (get_sub_field('sidebar_submenus') == 'sm-1') : ?>	
    $rows = get_field('submenus', 'option' );
    $specific_row = $rows[0];
    $sub_field_value = $specific_row['submenus_content'];
    $submenu = get_field( $sub_field_value, 'option' );
    <?php echo $submenu[0]; ?>	  
    <?php endif; ?> 

    Thank you very much in advance

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

You must be logged in to reply to this topic.

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.