Support

Account

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>';