Home › Forums › General Issues › only show published posts in Relationship / Post / Page Link picker etc › Reply To: only show published posts in Relationship / Post / Page Link picker etc
For anyone else facing the dilemma of ACF pushing links unpublished posts with the Page Link ACF type, here’s the work around I used.
The key here is permalinks. If you’re using pretty permalinks (and you should be) published posts will use the pretty permalinks, but unpublished posts won’t.
So, you can use PHP’s
strpos(); to check the variable for specific words in the course permalink. Here’s my example:
<?php // Get the Post ID $pid = get_field('course_selection', false, false); // Use that to generate the permalink $ppl = get_the_permalink($pid); // If the permalink (string) doesn't contain 'post_type' show it, cuz it's using pretty permalinks, and therefore has been published if(!strpos($ppl, 'post_type')): ?> // Your code here <?php endif; ?>
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!
© 2022 Advanced Custom Fields.