BUG: WooCommerce feature treats comma-separated taxonomy query vars (e.g. product_cat=a,b) as a single slug
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
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
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
- Install WooCommerce and ElasticPress, activate the WooCommerce feature and run a sync.
- Create two product categories, e.g.
shirtsandhoodies, each with some published products. - Visit
/?product_cat=shirtsand/?product_cat=hoodies: each lists its products. - Visit
/?product_cat=shirts,hoodies: "No products were found". - 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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 10up/ElasticPress
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
10up/ElasticPress#4402 · 1 comment ·
Maintainers usually reply within 2 days
-
BUG: `--nobulk` reports objects that fail to prepare as indexedPossibly taken @yograj-vijay-yadav claimed this 5 days ago. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
10up/ElasticPress#4393 · 1 comment ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
10up/ElasticPress#4390 ·
Maintainers usually reply within 2 days
-
[Release] 5.3.6Open
Difficulty 4/5 3-5 days Newbie friendliness 15/100
10up/ElasticPress#4388 ·
Maintainers usually reply within 2 days
-
Move AI Features from ElasticPress Labs to the ElasticPress PluginPossibly taken @ZacharyRener claimed this 122 days ago. Openenhancement
10up/ElasticPress#4316 · 2 comments · 1 assignee ·
Maintainers usually reply within 2 days
All issues in 10up/ElasticPress
Similar issues
-
enhancement priority Sales
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
novalo-dev/Prestashop-MCP-Server#201 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Include flows spanning the full report time windowPossibly taken @somethingwithproof claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Cacti/plugin_flowview#306 ·
Maintainers usually reply within 1 day
-
bug origin: upstream priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
mattytap/Mattytap-Sermons#105 ·
-
priority:low type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
crazy-goat/workerman-bundle#1189 ·
Maintainers usually reply within 1 day