Skip to content

Instantly share code, notes, and snippets.

@neilgee
Last active December 21, 2015 08:40
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 neilgee/3f4f6775ea60e327f6fb to your computer and use it in GitHub Desktop.
Save neilgee/3f4f6775ea60e327f6fb to your computer and use it in GitHub Desktop.
<?php //<~ don't add me in
function wpb_add_cpt_search($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post_type', array('page', 'post', 'custom-post-type-name'));
}
}
}
add_action('pre_get_posts','wpb_add_cpt_search');
<?php //<~ don't add me in
function wpb_remove_pages($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
}
}
add_action('pre_get_posts','wpb_remove_pages');
<?php //<~ don't add me in
function wpb_remove_posts($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post_type', 'page');
}
}
}
add_action('pre_get_posts','wpb_remove_posts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment