One way to exclude pages from search results is to install the Simply-Exclude plugin. Another solution I found to work pretty well is to add a filter in functions.php to only include posts categories instead of excluding pages from search results:
// Remove pages from search function mySearchPostsFilter($query) { if ($query->is_search) { $query->set('cat','12,14,16,17,18'); // your category IDs } return $query; } add_filter('pre_get_posts','mySearchPostsFilter'); |
That’s all! Replace the posts category IDs (‘12,14,16,17,18′) by your owns and it should work.
Popularity: 7% [?]


November 26th, 2008 at 10:02 pm
how do you exclude categories or posts?
I have found many plugins that will easily exclude pages. I’m looking for a pluglin to exclude posts.
know anything for that?
November 26th, 2008 at 10:23 pm
Well, this post explains how to exclude categories. To exclude posts, once I came across a plugin but I don’t remember its name.
Have you tried to search the Wordpress plugin directory?
Otherwise, ask on their forum. Someone might answer you. you can also search on Lorelle’s site. He always tells about the latest plugins.
May 13th, 2009 at 3:06 pm
sir, i am having problem in my search it shows only the post name but i want like the as it shows in the index page of my site systematically
July 23rd, 2009 at 7:55 pm
Instead of including categories you can also specify a post type. This example includes only posts and excludes pages:
$query->set(‘post_type’, ‘post’);
July 27th, 2009 at 8:48 am
Thanks Wouter for the tip.
February 9th, 2010 at 6:34 pm
[...] Dica retirada do site Web-Kreation [...]