I have a wordpress site in which I have setup a custom field show_post of type True / False.

Lets me control showing of posts of course.

But I can't figure out in php when using previous_post_link and next_post_link, to only showing posts that have the custom field show_post set as true.

Any ideas would be welcome especially if I am missing something simple.

  • Possible duplicate of if get_post_meta is empty do something – Max Yudin Mar 21 '19 at 16:49
  • This is not a possible duplicate of the question you linked to. It has nothing to do with "if get_post_meta is empty do something". Please reread it. – Mike Mar 21 '19 at 17:00
  • 1
    Custom field is post meta. You just should do the opposite: if get_post_meta is NOT empty do something. Or it's over-elaborated? – Max Yudin Mar 21 '19 at 17:05
  • 1
    Thanks for the welcome jsmod. get_post_meta() only returns data for the current post. I need to examine the data for both the next and previous post before I can decide what to do. – Mike Mar 21 '19 at 17:54
  • 1
    Yes when I click next/prev, I only want to see posts with a custom field "show_post" with value true. No posts with value of false will ever show up when next/prev clicked. Could I use the $excluded_terms argument in previous_post_link and next_post_link? – Mike Mar 21 '19 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.