Wordpress filter general search by post content type only

Categorías: 

Etiquetas: 

/**
 * Filter main search with post content type only
 * @param object $query
 * @return object
 */
function search_filter($query) {
    if ($query->is_search) {
        $query->set('post_type', 'post');
    }
    return $query;
}
add_filter('pre_get_posts','search_filter');