Created
October 20, 2011 02:55
-
-
Save jaredatch/1300302 to your computer and use it in GitHub Desktop.
Exclude category from search results in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/1301089