WordPress.org

Make WordPress Core

Opened 21 months ago

Last modified 34 hours ago

#18703 new defect (bug)

'pre_get_posts'-filter without effect when modifying 'tax_query'. Wrong parameters passed to 'parse_tax_query() ??; WP 3.2.1.

Reported by: xitromedia Owned by: info@…
Priority: normal Milestone: Awaiting Review
Component: General Version: 3.2.1
Severity: normal Keywords: reporter-feedback
Cc: tollmanz@…

Description

When modifying the 'tax_query' array directly with 'pre_get_posts' filter (e.g. setting 'include_children' to false), then it will firstly be modified in 'wp-includes/query.php' -> get_posts() after running the filter in line 1911.

But after line 2195 and running 'parse_tax_query' the 'tax_query' 'include_children'-parameter is unwanted reset/changed to the default value.

I think the bug is the following:

parse_tax_query() uses and needs values from the 'tax_query'-array but gets passed over only the 'query_vars'-array. so it resets the 'tax_query'-array-parameters in query.php line 1678 and hereby also the previously and individually set 'tax_query' values.

as far as i understand the core, i assume that any changes to the 'tax_query'-array with 'pre_get_posts'-filter will get lost and only changes to the 'query_vars'-array will take effect.

Change History (6)

comment:1 dd3221 months ago

  • Keywords reporter-feedback added

What's the exact use-case you're doing here? AFAIK, You shouldn't be modifying the tax_query for any core-handled tax queries, rather, you should be altering the query vars which create the tax query..

comment:2 xitromedia21 months ago

i want to force categories to not show posts of a child category. i think the parameter 'include_children' is made for this ?!

i found no other effective way to do this with 'pre_get_posts'.

comment:3 follow-up: dd3221 months ago

i think the parameter 'include_children' is made for this ?!

Yes, it is, but it shouldn't be modified the way you're doing it.

Instead, you should remove the 'cat' param, and set the 'category__in' param instead, which doesn't include children by default.

comment:4 xitromedia21 months ago

id did not find that rule in the documentation to not change the 'tax_query' parameter 'include_children'. what sense does it make if it must not be changed manually ?

but anyway....and only theoretically....i think the way i wanted to go by modifying the 'tax_query' should not harm in the state of 'pre_get_posts', if it is restricted to a specific category posts-query.
but this cannot work as expected because parse_tax_query() checks 'tax_query' although it never gets it (see my first post).
because of that any individual setting to 'include_children' - no matter whether done by me or by WP - will get lost/set to default i think.

comment:5 in reply to: ↑ 3 dpe41513 months ago

Replying to dd32:

Instead, you should remove the 'cat' param, and set the 'category__in' param instead, which doesn't include children by default.

This solution is fine for categories, but won't work/doesn't apply to custom taxonomies. Being able to modify include_children to exclude posts from child terms in a main custom taxonomies loop would be very, very helpful.

comment:6 tollmanz34 hours ago

  • Cc tollmanz@… added
Note: See TracTickets for help on using tickets.