I have a relationship field that outputs posts from a custom post type. However, if I unpublish one of those posts, it still shows in the outputted code.
I'm aware it's possible to set the fields to only allow the user to select from published posts only (in the admin), but I'm not sure how to add a check in the ACF output code to see if the posts are published or not.
The most likely situation where this will occur is when the client has been using the site for a while and using the relationship fields, but then deletes or unpublishes one of the posts and forgets to manually remove them from the relationship field.
Is there a way to check this on the fly?
<?php $holidays = get_sub_field('holidays'); if( $holidays ): ?> <?php foreach( $holidays as $holiday): ?> <?php setup_postdata($holiday); ?> <a href="<?php echo get_permalink( $holiday->ID ); ?>"> <?php echo get_the_title( $holiday->ID ); ?> </a> <?php endforeach; ?> <?php wp_reset_postdata(); ?>