Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Exclude category from search results in WordPress
<?php
add_filter( 'pre_get_posts', 'ja_search_filter' );
/**
* Exclude category 7 from search results.
*
* @since ?.?.?
* @author Jared Atchison
* @link https://gist.github.com/1300302
*
* @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;
}
@GaryJones

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.