Advertisement
Guest User

Untitled

a guest
Mar 24th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. // http://www.paulund.co.uk/include-all-custom-post-types-in-wordpress-search
  2. function mysite_include_post_types_in_search($query) {
  3.   if(is_search()) {
  4.     $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false), 'objects');
  5.     $searchable_types = array('nav_menu_item');
  6.     if($post_types) {
  7.       foreach( $post_types as $type) {
  8.         $searchable_types[] = $type->name;
  9.       }
  10.     }
  11.     $query->set('post_type', $searchable_types);
  12.   }
  13.   return $query;
  14. }
  15.  
  16. add_action('pre_get_posts', 'mysite_include_post_types_in_search');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement