Last active
January 17, 2016 20:13
-
-
Save vanbernaert/4015be9becf8e8b382c8 to your computer and use it in GitHub Desktop.
Exclude a (Custom) Post Type from WordPress Search Result
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
/* put function in functions.php */ | |
function exclude_from_search() { | |
global $wp_post_types; | |
/* exclude pages from search result */ | |
$wp_post_types['page']->exclude_from_search = true; | |
/* exclude posts from search result */ | |
$wp_post_types['post']->exclude_from_search = true; | |
/* exclude another custom post type from search result */ | |
$wp_post_types['name-of-custom-post-type']->exclude_from_search = true; | |
} | |
add_action('init', 'exclude_from_search'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment