Posted on December 2nd, 2008 in WP Tips-Tricks | 2,403 views

If you intend to exclude pages from search results, you can use the Simply-Exclude plugin. However, another solution that works pretty well is to add a filter in functions.php to only include posts categories instead of excluding pages from search results:

1
2
3
4
5
6
7
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');

Just replace the posts category IDs (’12,14,16,17,18′) by your owns and it should work. That’s all!

Sign up for News and Updates!
digg delicious stumbleupon technorati Google live facebook Sphinn Mixx newsvine reddit yahoomyweb

0 Responses to “WP Tip – Exclude pages from search results”

  1. There are no comments posted yet. Be the first one!

Leave a Reply

Comment moderation is currently enabled so comments with spammy words or a few links might be delayed. Please do not submit your comments twice, they will be approved soon.
Off Auto TELEX VNI VIQR VIQR*