Post Pic

How to: limit search to specific categories

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;
query_posts("s=$s&paged=$paged&cat=1,2,3");
endif; ?>

You're done! See you tomorrow ;)

One Response

Sep 13 2011 22:04

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

much thanks!

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required