WP Tip - Exclude pages from search results
December 2nd, 2008 |
Categories: WP Tips-Tricks
| 132 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!
Leave a comment
| Trackback












UNITED STATES
%BROWSER_NAME% %BROWSER_VERSION%[/BROWSER] [OS]
%OS_NAME% %OS_VERSION%[/OS]