Copy the following snippet and paste it into the code of your theme, preferably in the functions.php file:
/* Exclude a Category from Search Results */
add_filter( 'pre_get_posts' , 'search_exc_cats' );
function search_exc_cats( $query ) {
if( $query->is_admin )
return $query;
if( $query->is_search ) {
$query->set( 'category__not_in' , array( 30 ) ); // Cat ID
}
return $query;
}
Related Posts:
- Search for tags
- Filter taxonomy terms using multiple id in the edit-tags.php
- If search matches taxonomy
- Check for taxonomy archive on search results page
- How to make tags show up in search results?
- Search Media by taxonomy
- WP Search using taxonomy terms
- Change searching from world level to first letter
- Including taxonomy in searches
- What is the ‘selected’ parameter in wp_dropdown_categories() for?
- Display taxonomy terms when adding a link in the admin
- Custom Taxonomy WP_Query for All Terms in a Taxonomy?
- How does Woocommerce store variation attributes, and how can they be retrieved per-variation? [closed]
- Using pre_get_posts to set posts per page, how do I?
- Better way to enforce category hierarchy in post_categories_metabox?
- How to set a Preset category for custom post types?
- How to find objects by terms
- Add Thumbnail to wp_list_categories()
- Display Post by taxonomy and taxonomy child
- Update all posts at once
- How to get the last term from taxonomy?
- List post from current taxonomy children
- Get the term for an taxonomy archive when the term has no posts
- orphaned taxonomy terms remove by sql query
- has_term not working
- How to make checkboxes from taxonomy terms?
- How to output hierarchical taxonomy path, with only the deepest term assigned?
- Using pre_get_posts for taxonomy post count
- Order custom Taxomony alphabetically and reversal after clicking a button?
- Set attachment tags from attachment’s custom field data
- is_taxonomy is deprecated. What’s the alternative?
- Share the same comments between more pages
- How to add a class to term
- Return user taxonomies
- custom post type and taxonomy url rewrite without tax-name
- conditional statement based on terms
- Display specific taxonomy
- add upload image to default taxonomy
- Terms not appearing in wp_dropdown_categories
- Why does WP_Query strip colons from tag names?
- Syntax help needed: Taxonomy Query
- Help Understanding Taxonomy
- Expired event redirect to parent category
- Different permissions for same type of post
- custom taxonomy terms archive page
- Remove Category When Post Transitions from Status Private To Public And has Specific categories already?
- SQL query joining on taxonomy tables not returning what I would expect
- Taxonomy.php error appearing in the header of my site [closed]
- Counting posts by certain author with custom taxonomy
- How can I query all post with currrent taxonomy term?
- Can you have seperate sidebars for multiple taxonomy archives?
- How to order a taxonomy’s terms numerically, from lowest to highest using get_terms
- Displaying Custom Taxonomy Children in Dropdown
- Custom Taxonomy With Author?
- Exclude taxonomy term from list of current taxonomy terms
- Tags hierarchical
- Display List of All Taxomony Terms of A Post
- Exclude taxonomy Query if post_type
- WordPress how to prevent URL encoding in URL of taxonomy terms
- WP_Query, Taxonomy, list of attached items to a Term, sorted
- Rewrite slug for WP core taxonomies
- Query Two Different Taxonomies Nested
- $_POST sometimes empty even though isn’t when using edited_[taxonomy] hook
- ACF Taxonomy in Loop
- How to show only first, second, third Custom taxonomy conditionally
- Rewrite Search URL Permalink For CPT Custom Taxonomies
- Showing related post for custom taxonomy
- Noticed updating taxonomy terms take a long time and run out of memory
- How do I export categories, site stats, comments and posts from wordpress to excel
- List of all posts from current category on single portfolio page
- What is the use case for sharing a term between multiple taxonomies?
- Make taxonomy query dynamic
- How to show children terms even if they are empty
- show recently added tags to tag cloud
- WordPress get parent category taxonomy
- how to create custom taxonomy drop downs for parents and child
- How to exclude post-tag taxonomy for a custom post type?
- “If an object equals a term id then return the term name”
- Should i use usermeta or taxonomy (or even custom taxonomy)?
- Custom dropdown search form that allows users to select option B based from Option 1
- How do I echo all of my taxonomies?
- taxonomy tags..it is not working
- Search format not matching taxonomy query
- Why do my offline development site and online live site behave differently?
- WordPress bool(false) means taxonomy compare not working [duplicate]
- How to change value in wp-include/taxonomy.php without exchanging the WordPress-core
- How to perform a search inside a specific taxonomy category
- Store members in custom taxonomy or native user?
- Remove title attribute from tag cloud widget [duplicate]
- Taxonomy templates in a multilanguage site
- ?taxonomy_name=slug shows both posts and pages
- Echo used hierarchical taxonomies parent name
- Show min and max taxonomy values
- Implode Taxonomy to hide parents?
- Show Taxonomy Child Terms (name and image) on Parent Term Page
- Custom Search only for my Custom Taxonomy Page – data
- Unable to do WP_User_Query with meta filter
- Add URL field to wordpress taxonomy
- Using autocomplete with post_tag taxonomy on attachments
- Bulk import in custom taxonomy