[wp-trac] [WordPress Trac] #32526: Tax_Query doesn't working in switch_to_blog()

WordPress Trac noreply at wordpress.org
Fri May 29 15:09:38 UTC 2015


#32526: Tax_Query doesn't working in switch_to_blog()
--------------------------------+------------------------------
 Reporter:  phill_brown         |       Owner:
     Type:  defect (bug)        |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Networks and Sites  |     Version:  4.2.2
 Severity:  normal              |  Resolution:
 Keywords:                      |     Focuses:  multisite
--------------------------------+------------------------------
Description changed by ocean90:

Old description:

> Scenario:
>
> * Site 1 has registered taxonomy called news_category. Site 2 hasn't.
> * Site 2 runs `switch_to_blog(1);`
> * Site 2 runs WP_Query with a tax_query parameter
>
> eg
> {{{
> #!php
> $news = new WP_Query([
>     'post_type' => 'news',
>     'tax_query' => [
>         [
>             'taxonomy' => 'news_category',
>             'field' => 'slug',
>             'terms' => 'wordpress',
>         ]
>     ]
> ]);
> }}}
>
> The above query returns 0 results because the tax_query portion errors
> and fails the WHERE clause. In this case, it's caused when the
> clean_query method fails a call to `taxonomy_exists()`. Taxonomy_exists
> is also baked into the logic of other subsequent functions in that method
> such as `is_taxonomy_hierarchical' and `get_term_children`.
>
> This looks to be a far-reaching issue related to a ticket raised and
> closed years ago: https://core.trac.wordpress.org/ticket/20541.
>
> I've attached a patch which may resolve the issue specific to Tax_Query.

New description:

 Scenario:

 * Site 1 has registered taxonomy called news_category. Site 2 hasn't.
 * Site 2 runs `switch_to_blog(1);`
 * Site 2 runs WP_Query with a tax_query parameter

 eg
 {{{
 #!php
 $news = new WP_Query([
     'post_type' => 'news',
     'tax_query' => [
         [
             'taxonomy' => 'news_category',
             'field' => 'slug',
             'terms' => 'wordpress',
         ]
     ]
 ]);
 }}}

 The above query returns 0 results because the tax_query portion errors and
 fails the WHERE clause. In this case, it's caused when the clean_query
 method fails a call to `taxonomy_exists()`. Taxonomy_exists is also baked
 into the logic of other subsequent functions in that method such as
 `is_taxonomy_hierarchical` and `get_term_children`.

 This looks to be a far-reaching issue related to a ticket raised and
 closed years ago: #20541.

 I've attached a patch which may resolve the issue specific to Tax_Query.

--

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32526#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list