I have a repeater with a single sub field that is a post object. Code starts with:
if( have_rows('you_may_also_like') ):
The post object selected for the repeater are Ingredient pages. The repeater is on a Recipe page.
Say we add the Ingredient post for flake powder to the repeater on a Recipe page. Later, the post for flake powder itself is deleted, but the repeater on the Recipe page is unchanged.
When we load the Recipe page, while it will no longer show the post object for the flake powder post, it will show the post object for the Recipe page that the repeater is on. This only happens when an Ingredient post has been deleted and the corresponding row in the repeater has not been deleted.
Given it is not always easy to know which Ingredient posts appear on which Recipe pages, is there a way to do a check such that if there is a row still on a repeater for a post object where that post itself has been deleted to then not display anything?
if (have_rows('repeater')) {
while(have_rows('repeater')) {
the_row();
if (empty(get_field('post_object'))) {
// post object does not exist
continue;
}
// remainder of code for showing the row
}
}