pengume
Member
Posted 2 years ago #
Hello everyone,
I tried using the template tag query_posts("cat=-7");
to make it so my search results did not get that category id 7, however now the search results don't really work it just searches one category( it seems) and doesn't have pagination. I am new to PHP but understand a little.
Does anyone have any idea or know how to accomplish what I am looking for.
Thanks,
Aaron
Try this instead.
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( 1, 2, 3 ) ); // Example multiple cats
$query->set( 'category__not_in' , array( 1 ) ); // Single cat
}
return $query;
}
In your functions.php (of your theme) is fine.
Thanks that worked perfect for me. Thanks for the snippit of code.