Created
September 20, 2018 14:11
-
-
Save Garconis/2d1bc61fb4a4ed257d6a679f906a6ee1 to your computer and use it in GitHub Desktop.
WordPress | Exclude certain Custom Post Types from search
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
<?php | |
// include only certain post types in the search results | |
function gc_filter_search($query) { | |
if (!$query->is_admin && $query->is_search) { | |
$query->set('post_type', array('post', 'page', 'book')); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts', 'gc_filter_search'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment