[wp-trac] [WordPress Trac] #42732: Problem with usage of WP_Term_Query inside WP_Tax_Query

WordPress Trac noreply at wordpress.org
Tue Nov 28 15:15:23 UTC 2017


#42732: Problem with usage of WP_Term_Query inside WP_Tax_Query
--------------------------+-----------------------------
 Reporter:  strategio     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  4.9
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42732>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list