• Skip to main content
  • Skip to primary sidebar

Supplemental Resources

Just The Tech, News, and Info We Deem To Post

  • Home
  • Home
  • Home
  • Home
  • Home
  • Home
  • Home
  • Home
  • Home
  • About
  • About
  • About
  • About
  • About
  • About
  • About
  • About
  • About
  • Contact
  • Contact
  • Contact
  • Contact
  • Contact
  • Contact
  • Contact
  • Contact
  • Contact
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • Contribute
  • WordPress
  • Marketing
  • Business
  • Computing
  • Security
  • Publicity
  • Resources
  • WHATEVS

Exclude Categories from Search in WordPress

Matrix Style Image Representing WordPress Code Snippet

Insert the code snippet into your theme’s functions.php, a helper file, or a functionality plugin to exclude specific categories from being displayed in WordPress search results. Apply the following code snippet to your theme’s functions.php, included helper functions, or a functionality plugin.

X where X is the number/ID of your category, comma separated for multiple.

function SearchFilter($query) {
    if ($query->is_search) {
        $query->set('cat','-X');
    }
    return $query;
}
add_filter('pre_get_posts','SearchFilter');

by Jack Alltrade on September 6, 2022

Filed Under: Code Snippets Tagged With: Categories, Exclude, WP Core

Reader Interactions

Share Your Two Cents Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

© Copyright Jack Alltrade & Associates 2026 · Purely Supplemental™ is a trademark of Jack Alltrade & Associates