Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Forked from jaredatch/gist:1300302
Created October 20, 2011 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GaryJones/1301089 to your computer and use it in GitHub Desktop.
Save GaryJones/1301089 to your computer and use it in GitHub Desktop.
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( WP_Query $query ) {
if ( $query->is_search )
$query->set( 'cat', '-7' );
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment