Home Forums Trusted Pro Search pop-up misbehavior… pull down does not work. Reply To: Search pop-up misbehavior… pull down does not work.

#3990
Andy
Keymaster

You just need to add this to exclude products where the ‘product_visibility’ taxonomy is set to ‘exclude-from-search’:

$query->set( 'tax_query', array(
    array(
    'taxonomy' => 'product_visibility',
    'field'    => 'name',
    'terms'    => 'exclude-from-search',
    'operator' => 'NOT IN',
    )
) );

So the full code using the previous example would be:

function trusted_custom_search_filter( $query ) {
    if ( $query->is_search ) {
        $query->set( 'post_type', array( 'recipe', 'post', 'product' ) );
        $query->set( 'tax_query', array(
            array(
            'taxonomy' => 'product_visibility',
            'field'    => 'name',
            'terms'    => 'exclude-from-search',
            'operator' => 'NOT IN',
            )
        ) );
    }
    return $query;
}
add_filter( 'pre_get_posts', 'trusted_custom_search_filter' );