Home › Forums › ACF PRO › if (have_rows()) not working › Reply To: if (have_rows()) not working
I have a similar issue having just updated to 5.1.1. I have a banner gallery assigned to every page using a Repeater Field with a fallback to the gallery assigned to the home page if no images have been uploaded to the individual page.
If I add and then delete images from a page gallery (have_rows()) appears to still be returning true even though images are no longer assigned to the page and I’ve removed the row(s) from the admin area (and saved the page), so I get no fallback banner gallery output on the pages.
echo '<div id="banner">';
if( have_rows('banner_gallery')){
while( have_rows('banner_gallery') ): the_row();
$image = wp_get_attachment_image_src(get_sub_field('banner_image'), 'bannerwide-image');
echo '<img src="'.$image[0].'" />';
endwhile;
} else { // show the gallery images assigned to home page (ID 2)
while( have_rows('banner_gallery',2)): the_row();
$image = wp_get_attachment_image_src(get_sub_field('banner_image'), 'bannerwide-image');
echo '<img src="'.$image[0].'" />';
endwhile;
}
echo '</div>';
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.