Skip to content

Instantly share code, notes, and snippets.

@neilgee
Last active Dec 21, 2015
Embed
What would you like to do?
<?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