WordPress Custom Post Types Custom post type in default search


Example

You can add custom post type posts on default wordpress search, Add below code in theme functions.php

function my_search_filter($query) {
  if ( !is_admin() && $query->is_main_query() ) {
    if ($query->is_search) {
      $query->set('post_type', array( 'news','post','article' ) );
    }
  }
}
add_action('pre_get_posts','my_search_filter');