Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Last active April 16, 2019 14:06
Show Gist options
  • Save leepettijohn/506184e1882d3a5317a8 to your computer and use it in GitHub Desktop.
Save leepettijohn/506184e1882d3a5317a8 to your computer and use it in GitHub Desktop.
Exclude specific pages from search query
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