Created
December 9, 2020 12:41
-
-
Save smileBeda/20b7a0f75ba8dd18d2884370de7de779 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
add_action( 'pre_get_posts', 'remove_post_type_from_front_end_search_results'); | |
function remove_post_type_from_front_end_search_results($query){ | |
if(is_admin() || !$query->is_main_query()) return; | |
if($query->is_search()){ | |
$post_type_to_remove = 'your_post_type'; | |
$searchable_post_types = get_post_types(array('exclude_from_search' => false)); | |
if(is_array($searchable_post_types) && in_array($post_type_to_remove, $searchable_post_types)){ | |
unset( $searchable_post_types[ $post_type_to_remove ] ); | |
$query->set('your_post_type', $searchable_post_types); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment