Limit search to specific categories of wordpress

January 23, 2009 · Print This Article

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.

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; ?>


Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.