Support

Account

Home Forums ACF PRO Getting first row of Repeater with the_row_index() Reply To: Getting first row of Repeater with the_row_index()

  • The function will only return the current index of the active loop. Basically you cannot access fields in a repeater without having an active have_rows() loop. This works the same as the WP have_posts() loop. Without a loop, many of the functions in WP will not work because they are only designed to work inside the loop.

    
    // accessing only the first row of a repeater
    if (have_rows('repeater')) {
      while (have_rows('repeater')) {
        the_row();
        the_sub_field('sub_field_name');
        // after doing what you want to do with the fist element
        break;
      }
    }
    // if you want you can reset the above row to 
    // begin from the first row again
    reset_rows();
    // start another loop on the same field
    // if you don't use reset above then it will
    // start with the second row
    if (have_rows('repeater')) {
      // etc....
    }