Last active
April 16, 2019 14:06
-
-
Save leepettijohn/506184e1882d3a5317a8 to your computer and use it in GitHub Desktop.
Exclude specific pages from search query
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
function jp_search_filter( $query ) { | |
if ( $query->is_search && $query->is_main_query() ) { | |
// unset certain pages | |
$query->set( 'post__not_in', array( 10,11,20,105 ) ); | |
// setup certain categories | |
$query->set('cat',array('stores')); | |
// setup certain post types | |
$query->set( 'post_type', array( 'post', 'movies', 'products', 'portfolio' ) ); | |
} | |
} | |
add_filter( 'pre_get_posts', 'jp_search_filter' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment