Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Exclude category from search results in WordPress
add_filter( 'pre_get_posts', 'ja_search_filter' );
* Exclude category 7 from search results.
* @since ?.?.?
* @author Jared Atchison
* @link
* @param WP_Query $query Existing query object
* @return WP_Query Amended query object
function ja_search_filter( $query ) {
if ( $query->is_search && !is_admin() )
$query->set( 'cat','-7' );
return $query;

This comment has been minimized.

Copy link

@GaryJones GaryJones commented Oct 20, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.