Home › Forums › Add-ons › Repeater Field › Why we need check have_rows('parent_field') two times? › Reply To: Why we need check have_rows('parent_field') two times?
For the same reason that in WP you do
if (have_posts()) {
while(have_posts()) {
the_post();
}
}
What if you want to do something outside the while loop but only if there are rows? What if you want to do something different if there are not rows?
if (have_rows('field')) {
// do something here before the loop
while(have_rows('field')) {
the_row();
}
// do something here after the loop
} else {
// do something different if there are not rows
}
Just like you can skip if (have_posts())
you can skip if(have_rows())
if you’re sure you don’t care what happens if there are none.
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.