Last active
December 21, 2015 08:40
-
-
Save neilgee/3f4f6775ea60e327f6fb to your computer and use it in GitHub Desktop.
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
<?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'); |
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
<?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'); |
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
<?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