Posted By

creativelifeform on 06/02/10


Tagged

wordpress


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

BrianCoyDesign
artificialid
maxvee8
booski
srdjan


Exclude specific category from Search Results in Wordpress


 / Published in: PHP
 

Found this bit of code all over the place, except it missed out a very crucial part of the code which was to add a "-" in front of the ID you wish to exclude. Add this to functions.php in your theme folder.

  1. function SearchFilter($query)
  2. {
  3. if ($query->is_search)
  4. {
  5. $query->set('cat',-get_cat_ID('CategoryName'));
  6. }
  7. return $query;
  8. }
  9. add_filter('pre_get_posts','SearchFilter');

Report this snippet  

You need to login to post a comment.