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!












UNITED STATES and using
0 Responses to “WP Tip – Exclude pages from search results”