Filter search results by post type

function search_posts_filter( $query ){
    if ($query->is_search){
        $query->set('post_type',array('post','custom_post_type1', 'custom_post_type2'));
    }
    return $query;
}
add_filter('pre_get_posts','search_posts_filter');

Leave a Reply