Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created October 20, 2011 02:55
Show Gist options
  • Save jaredatch/1300302 to your computer and use it in GitHub Desktop.
Save jaredatch/1300302 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( $query ) {
if ( $query->is_search && !is_admin() )
$query->set( 'cat','-7' );
return $query;
}
@GaryJones
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment