php查询,一次只能工作一次

I using this php filter for search box in my wp website. I know this is wrong because the filter show me only the last query, how I can write the code in the way both query work?

function SearchFilter($query) {
    if ($query->is_search) {
           $query->set('post_type', 'post');
           $query->set('post_type', 'course');
       }
    return $query;
}
add_filter('pre_get_posts','SearchFilter'); 

Thank you.

You are setting the $query every time on the last post_type which is of(course) wrong .

Change it to

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