• Resolved Daniel Delos

    (@alteritydan)


    I want to exclude specific pages OR all pages from wordpress on-site search. Basically I want them only accessible through having their exact URL. Alternatively, I want WP search to ONLY show pages.

    Seems like it should be very simple. But over the last few hours I have tried every plugin claiming to do any of these things (they don’t work with the latest wordpress version without exception). I have tested numerous methods that worked even up to a month ago. They don’t now.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator t-p

    (@t-p)

    try adding this to your theme’s functions.php:

    function my_search_filter($wp_query) {
       if ($wp_query->is_search) {
          $wp_query->set('post__not_in', array( -101 ) );
       }
       return $wp_query;
    }
    add_filter('pre_get_posts','my_search_filter');

    where -101 is the post or page ID. change it your page id.

    Thread Starter Daniel Delos

    (@alteritydan)

    Thanks for the suggestion, I hope it will help anyone else searching. I came up with a different solution. I’m just using a subdomain for the form pages that I needed removed from the search.

    Moderator t-p

    (@t-p)

    Glad you got it sorted ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Possible to Exclude Pages from WP Search?’ is closed to new replies.