BUG: WooCommerce feature treats comma-separated taxonomy query vars (e.g. product_cat=a,b) as a single slug

Open
#4,400 1 comment 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 2 days

@felipeelia is already working on this.

Since Nov 3, 2026.

  • #4401 by @yograj-vijay-yadav — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
elasticsearch, php
Domain
backend, search

Research direction

Find Products::maybe_update_tax_query() in the WooCommerce feature and compare its handling of taxonomy query vars with the WordPress core behavior described in the issue. Reproduce the comma-separated case and check how + should behave. Done means queries return the expected products for both separators without breaking single-term or array values.

Written by the indexing model from the issue text.

Description

bug
Describe the bug

With the WooCommerce feature active, a product query that uses a taxonomy query var with several comma-separated terms (e.g. ?product_cat=shirts,hoodies) returns no results. Without ElasticPress, WordPress returns the products of either term.

Products::maybe_update_tax_query() copies each supported taxonomy query var into tax_query as-is:

$term = $query->get( $taxonomy, false );
if ( ! empty( $term ) ) {
    $tax_query[] = array(
        'taxonomy' => $taxonomy,
        'field'    => 'slug',
        'terms'    => (array) $term,
    );
}

So shirts,hoodies becomes 'terms' => [ 'shirts,hoodies' ]. The slug is then sanitized to shirtshoodies, matches nothing, and the query returns nothing.

WordPress core reads a comma in a taxonomy query var as OR and + as AND (WP_Query::parse_tax_query()), so I expected the same results as MySQL. + is not handled either.

We ran into this through a filter plugin (HUSKY – Products Filter for WooCommerce) that puts multi-select filters in the URL as taxonomy query vars. The plugin's own tax_query clause is correct, but the extra clause added here empties the result. It also happens without that plugin, as below.

The same code is still on develop.

Steps to Reproduce
  1. Install WooCommerce and ElasticPress, activate the WooCommerce feature and run a sync.
  2. Create two product categories, e.g. shirts and hoodies, each with some published products.
  3. Visit /?product_cat=shirts and /?product_cat=hoodies: each lists its products.
  4. Visit /?product_cat=shirts,hoodies: "No products were found".
  5. Turn the WooCommerce feature off (or deactivate ElasticPress) and repeat step 4: the products of both categories are listed.

In our test the two categories returned 542 and 653 products on their own; the combined URL returned 0 with ElasticPress and 1,195 without it.

Screenshots, screen recording, code snippet

Possible fix, mirroring core's parsing in maybe_update_tax_query():

$term = $query->get( $taxonomy, false );
if ( empty( $term ) ) {
    continue;
}

if ( is_string( $term ) && str_contains( $term, '+' ) ) {
    foreach ( preg_split( '/[+]+/', $term ) as $single ) {
        $tax_query[] = [
            'taxonomy' => $taxonomy,
            'field'    => 'slug',
            'terms'    => [ trim( $single ) ],
        ];
    }
} else {
    $tax_query[] = [
        'taxonomy' => $taxonomy,
        'field'    => 'slug',
        'terms'    => is_array( $term ) ? $term : array_map( 'trim', preg_split( '/[,]+/', $term ) ),
    ];
}
Environment information

Server-side issue, not browser-specific.

  • WordPress 7.1.3
  • WooCommerce 11.2.1
  • ElasticPress 5.3.5
  • Elasticsearch 8.17.4 (self-hosted)
  • PHP 8.3
WordPress and ElasticPress information

No response

Code of Conduct
  • I agree to follow this project's Code of Conduct
Dominant language
PHP
Stars
1.3k
Forks
325
Avg merge
2d 12h
Merged PRs (30d)
19

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from 10up/ElasticPress

All issues in 10up/ElasticPress

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.