Exclude Pages or Posts From Search Results For Logged In Users

This PHP code once added to the end of your child themes functions.php file excludes all pages from inclusion in the search results when using the native WordPress search function.

The code below only excludes an array of specific post I.D’s from the search results.


Comments

2 responses to “Exclude Pages or Posts From Search Results For Logged In Users”

  1. Brian Thomas Avatar
    Brian Thomas

    Hello is it possible to do the opposite of this fix? I want pages that are restricted to “subscribers” to be hidden from the search results for non logged-in users, but become visible in the search results for logged-in subscribers. I’m using the Metro Pro Theme along with the UserPro plugin. Any suggestions?

    1. Hi Brian. Try adding the PHP not operator to the conditional tag like this

      [code]! is_user_logged_in()[/code]

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.