Posted By

Jamie on 08/25/10


Tagged

post wordpress type custom


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

aleprieto
crypticsoft
srdjan


Filter WordPress Search Results By Post Type


 / Published in: PHP
 

  1. // Only search posts, and custom post types, excluding pages
  2. function search_posts_filter( $query ){
  3. if ($query->is_search){
  4. $query->set('post_type',array('post','custom_post1', 'custom_post2'));
  5. }
  6. return $query;
  7. }
  8. add_filter('pre_get_posts','search_posts_filter');

Report this snippet  

You need to login to post a comment.