• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2762

Original Genesis Tutorials & 6000+ Guaranteed Code

Snippets

  • Premium Access
  • Log in

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.

Subscribe for new Tutorials

Reader Interactions

Comments

  1. Brian Thomas says

    January 19, 2018 at 3:49 am

    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?

    Log in to Reply
    • Brad Dalton says

      January 19, 2018 at 3:57 am

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

      ! is_user_logged_in()
      Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting