Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://www.paulund.co.uk/include-all-custom-post-types-in-wordpress-search
- function mysite_include_post_types_in_search($query) {
- if(is_search()) {
- $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false), 'objects');
- $searchable_types = array('nav_menu_item');
- if($post_types) {
- foreach( $post_types as $type) {
- $searchable_types[] = $type->name;
- }
- }
- $query->set('post_type', $searchable_types);
- }
- return $query;
- }
- add_action('pre_get_posts', 'mysite_include_post_types_in_search');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement