[wp-trac] [WordPress Trac] #16814: WP_Query doesn't check orderby for meta_query
WordPress Trac
noreply at wordpress.org
Fri Oct 3 14:01:07 UTC 2014
#16814: WP_Query doesn't check orderby for meta_query
--------------------------+-----------------------
Reporter: dalesaurus | Owner:
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 4.1
Component: Query | Version: 3.1
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+-----------------------
Changes (by boonebgorges):
* milestone: Awaiting Review => 4.1
Comment:
Confirmed. Good catch.
Your fix looks correct to me. To spell it out a bit more for posterity:
when passing `meta_key`, etc to `WP_Query`, they are parsed into a
`WP_Meta_Query` object:
https://core.trac.wordpress.org/browser/tags/4.0/src/wp-
includes/query.php#L2377. Any combination of `meta_key`, `meta_value` etc
that were passed to `WP_Query` always gets set as the 0th member of the
`meta_query->queries` array. So looking at the 0th index, as in your
patch, will find the right orderby regardless of whether you're using
`meta_key` etc or a proper `meta_query` param.
[attachment:16814.2.patch] adds another assertion to your test, to show
how the `meta_key` gets parsed together with, and takes precedence over,
the `meta_query` arguments.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/16814#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list