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....
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.