Opened 8 years ago
#42732 new defect (bug)
Problem with usage of WP_Term_Query inside WP_Tax_Query
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 4.9 |
| Component: | Query | Keywords: | |
| Focuses: | Cc: |
Description
This problem started on WP 4.9 because of #37038.
In WPML plugin, we filter the tax queries in order to convert the term IDs to their translations in the current language (if any).
In WP 4.8.3, WP_Tax_Query::transform_query was making direct calls to the DB.
In WP 4.9, WP_Tax_Query::transform_query is using WP_Term_Query to fetch the terms of the meta query.
The problem is that we have filters on WP_Term_Query (on get_terms_args) which applies to this.
This is usually not a problem, except for a post query with tax queries and suppress_filters set to true.
Here's an example:
$args = array(
'post_type' => 'post',
'suppress_filters' => true,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => [ 3, 4 ] // 3 is the English category and 4 is the translation in French
),
)
);
$wp_query = new WP_Query( $args );
What is expected (and actual behavior in 4.8.3): This query should return all the posts attached to the category 3 or 4, whatever the current language.
What we have now: The query returns the posts attached to 3 OR the posts attached to 4 (depending on the current language).
So we need a way to flag that WP_Term_Query is used inside WP_Query (via WP_Tax_Query) and suppress_filters is set to true.