[wp-trac] [WordPress Trac] #39140: Taxonomies - operator AND doesn't work properly for taxonomy hierarchies
WordPress Trac
noreply at wordpress.org
Wed Dec 7 08:54:33 UTC 2016
#39140: Taxonomies - operator AND doesn't work properly for taxonomy hierarchies
--------------------------+-----------------------------
Reporter: bredefladen | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 4.6.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Hi,
This is a problem discovered using WooCommerce shortcodes but has its core
problem in the WP core according to my findings. I've already implemented
a fix for this in a customer project.
I’ve ran into problems using one of the Woo shortcodes and operator ‘AND’.
This is questioned by others several times before (see links below) but it
seems like the core of the problem is not solved. I’ve worked with the
issue on WP 4.6.1 installation and come to what I believe is a solution
(changes in file class-wp-tax-query.php).
Even if the issue is found using Woo product categories I believe this is
an issue for taxonomies in general.
Problem:
Using shortcode to retrieve a filtered product list and filtering on two
or more product categories using operator “AND” fails when using one or
more non-leaf (i.e. parent) product categories. There even seemed to be
additional problems when using more than two leaf keywords. In general the
"AND" didn't behave as expected.
Other reports on the issue:
[https://wordpress.org/support/topic/operator-and-on-product_category/]
[https://wordpress.org/support/topic/woocommerce-display-products-from-
two-categories-combined/]
[https://wordpress.org/support/topic/woocommerce-product_category-and-
operator-returns-no-results/]
Examples using Woo shortcodes:
Taxonomies (product categories) for Product1: '''Leaf'''CatA,
'''Leaf'''CatB
[product_category category=”'''Parent'''CatA, '''Leaf'''CatB”
operator=”AND”] => '''Fails''' - shows nothing. Should show Product1
[product_category category=”'''Leaf'''CatA, '''Leaf'''CatB”
operator=”AND”] => '''Ok''' - shows Product1
Reason:
There is no individual and complete hierarchial evaluation of each
taxonomy/category keyword specified in the shortcode.
Solution that worked for me:
The issue is found in the WP-core file class-wp-tax-query.php. I’ve
modified three functions to correct the issue. This includes changes to
the SQL-statements generated.
Changes to file class-wp-tax-query.php:
class WP_Tax_Query
- function get_sql_for_clause – code
- function clean_query – input params and code
- function transform_query – input params and code
You find my modified and running code/functions with my comments here
(tagged with // BF):
[https://gist.github.com/Nettsidespesialisten/5d4596e18dced3c7d97501f195ffe02e]
This is my first ticket here so please notify me how to contribute the
best way with this issue (providing code into SVN or other).
Kind regards
Brede
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39140>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list