I want to exclude pages and gallery post format from search results, so only show standard blog posts.

I tried this but it is still showing pages in the results

function filter_search( $query ) {
    if( $query->is_main_query() && $query->is_search() ) {

        $tax_query = array( array(
            'taxonomy' => 'post_format',
            'field' => 'slug',
            'terms' => array( 'post-format-gallery' ),
            'post_type' => array('page'),
            'operator' => 'NOT IN',
         ) );


         $query->set( 'tax_query', $tax_query );
    }

}
add_action( 'pre_get_posts', 'filter_search' );

0 Answers