Tuesday, October 4
Shadow

WordPress filter search results by post type

function filter_search_results( $query ) {
    if ( $query->is_search() && $query->is_main_query() && ! is_admin() ) {
        $query->set( 'post_type', 'post' ); // change this, can support multiple post types
    }
}
add_filter( 'pre_get_posts','filter_search_results' );

Leave a Reply