• Please, advise if it’s possible to exclude certain Woocommerce product categories from the frontend search results using Relevanssi plugin.

    How to?

    Thank you.

Viewing 1 replies (of 1 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Yes, you can. It happens exactly as it does in the WP default search, using taxonomy parameters. See documentation here. For example, to exclude product categories 5 and 7, you can use:

    add_filter( 'relevanssi_modify_wp_query', function( $query ) {
    $tax_query = array(
    array(
    'taxonomy' => 'product_cat',
    'terms' => array( 5, 7 ),
    'operator' => 'NOT IN',
    'field' => 'term_id',
    )
    );
    $query->set( 'tax_query', $tax_query );
    return $query;
    } );
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.