<?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');
<?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_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');