[wp-trac] [WordPress Trac] #18703: 'pre_get_posts'-filter without effect when modifying 'tax_query'. Wrong parameters passed to 'parse_tax_query() ??; WP 3.2.1.

WordPress Trac noreply at wordpress.org
Sat Aug 10 21:55:03 UTC 2013


#18703: 'pre_get_posts'-filter without effect when modifying 'tax_query'. Wrong
parameters passed to 'parse_tax_query() ??; WP 3.2.1.
--------------------------+---------------------
 Reporter:  xitromedia    |       Owner:  info@…
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  3.7
Component:  Query         |     Version:  3.2.1
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |
--------------------------+---------------------
Changes (by wonderboymusic):

 * keywords:  needs-patch => has-patch
 * milestone:  Awaiting Review => 3.7


Comment:

 Man this was obnoxious to track down - moral of the story:
 `parse_tax_query` needs an action at the end of the method just like
 `parse_query` has

 That allows you to alter `$query->tax_query->queries` like so:

 {{{
 add_action( 'parse_tax_query', function ( &$query ) {
         if ( ! is_admin() && $query->is_category && ! empty(
 $query->tax_query->queries ) ) {
                 foreach ( $query->tax_query->queries as &$tq ) {
                         if ( 'category' === $tq['taxonomy'] )
                                 $tq['include_children'] = false;
                 }
         }
 } );
 }}}

 Added a patch.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/18703#comment:10>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list