Support » Fixing WordPress » Take pages out of Search

  • Hey Guys,

    I’m trying to find a way to take pages out of the search results. I know there are a lot of posts about this topic already, and I’ve read most of them, but I still need some help. Sorry, novice programmer.

    I searched the board and tried to solve this problem using the Search Everything plugin, but instead of excluding a certain page ID from my results, I started getting “no results” for everything. Is there another plugin that can help me out here?

    Thanks!

Viewing 1 replies (of 1 total)
  • Found a great tutorial for excluding pages from search results here.

    The following function just needs adding to your theme’s functions.php file (create one if it doesn’t exist).

    <?php
    function mySearchFilter($query) {
    	if ($query->is_search) {
    		$query->set('post_type', 'post');
    	}
    	return $query;
    }
    
    add_filter('pre_get_posts','mySearchFilter');
    ?>

    Should be possible to adapt to exclude selected posts also but I’m a novice too and haven’t managed to figure it out yet.

    I’d be very interested to know how to combine the page exclude function above with the ability to exclude posts by tag. I’m guessing there’s a simple solution?

Viewing 1 replies (of 1 total)
  • The topic ‘Take pages out of Search’ is closed to new replies.