I recently came up with a scenario on a website I created using WordPress which needed me to prevent protected posts from displaying in search results or on the blog index page. Initially, I thought this would be a setting on a per post page but alas, WordPress does not have the feature built-in.

After much research I found that one could actually remove protected posts entirely before the query actually took place (read: nice and efficient). To do so, I just had to pop the following code into my functions.php theme file and immediately got to watch my protected posts actually being protected from the public eye 😉

Let me know if you implement this code and how it works for you. Would love to see it in action 😀

Published by Seagyn

I'm a passionate "Maker of Things" and build as often as I can. I build things with mainly with PHP and a little Javascript. View more posts

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.