DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

If for some reason, you’d like to exclude some categories from searches, you have to tweak WordPress a bit because there’s no built-in solution to this problem. Happilly, here’s a code to do that job!

To achieve this recipe, replace the categories IDs on line 3 and paste the following code on your search.php template:

<?php if( is_search() )  :
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
endif; ?>

You’re done! See you tomorrow 😉



  1. Hi is there a way to use the code above to actually sort the category in a specific order?

    much thanks!

  2. Thanks so much for this tip! Worked great.
    Just to clarify for others, the category IDs you need to list here are the categories to INCLUDE, not exclude, as this suggests.

  3. This recipe needs an update. Calling query_posts after the query has already been completed isn’t as efficient as using pre_get_posts.

Leave a Comment

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