Title: exclude from search
Last modified: August 20, 2016

---

# exclude from search

 *  [kortschot](https://wordpress.org/support/users/kortschot/)
 * (@kortschot)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/exclude-from-search-1/)
 * Hé there,
 * Got a little PHP question..
 * I want to exclude a category from my search results. But can’t do it by ID.
 *     ```
       function myFunctionName($query)
   
       {
       if ($query->is_search)
       {
       $query->set('cat','-'.$get_cat_id('category name').'');
       }
       return $query;
       }
       add_filter('pre_get_posts','myFunctionName');
       ```
   
 * I’m not a php wizard.. but i’m guessing the snag is in:
 *     ```
       $query->set('cat','-'.$get_cat_id('category name').'');
       ```
   
 * I tried
 *     ```
       $query->set('cat','-24');
       ```
   
 * Which works, but since I have some more installations of the same theme coming
   in the next month’s I want it to work on the category name instead of the ID.
   Due the ID won’t be the same in every installation and the name will.
 * Thanks!
 * Paul

The topic ‘exclude from search’ is closed to new replies.

## Tags

 * [exclude](https://wordpress.org/support/topic-tag/exclude/)
 * [exclude category](https://wordpress.org/support/topic-tag/exclude-category/)

 * 0 replies
 * 1 participant
 * Last reply from: [kortschot](https://wordpress.org/support/users/kortschot/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/exclude-from-search-1/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
