[wp-trac] [WordPress Trac] #31045: Ordering a Query Using Multiple Meta Keys

WordPress Trac noreply at wordpress.org
Wed Jan 28 18:27:23 UTC 2015


#31045: Ordering a Query Using Multiple Meta Keys
-----------------------------+-----------------------------
 Reporter:  Funkatronic      |       Owner:
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Future Release
Component:  Query            |     Version:  trunk
 Severity:  normal           |  Resolution:
 Keywords:  has-patch        |     Focuses:
-----------------------------+-----------------------------
Changes (by boonebgorges):

 * keywords:  needs-patch needs-unit-tests => has-patch


Comment:

 Thanks for these patches. I started working on your patch last night, and
 it wasn't working properly for me - but maybe this was fixed by your
 version 2 :)

 In any case, in the process of playing with table aliases, I started to
 have second thoughts. The way table aliases are currently built in
 `WP_Meta_Query` is like this: the first JOINed table is aliased as
 `$wpdb->postmeta`, and subsequent tables as `mt1`, `mt2`, etc. That first
 "unaliased" JOIN is then referenced in a number of places in `WP_Query`,
 and my guess is that there are plugins that are depending on it as well.
 For this reason, I'm hesitant to change table aliases. And,
 notwithstanding my earlier comments, it's not really necessary for what we
 want to accomplish here anyway.

 [attachment:31045.diff] takes a slightly different tack. Aliases are built
 in the same way as before. Meta queries now accept a `'name'` parameter.
 The meta query object now has a method `get_clauses()` which returns a
 flattened array of query clauses. This array is keyed by 'name', and
 contains 'cast' values, which are then used by `WP_Query` to build the
 ORDER BY clause. See the unit tests for examples.

 What do you think?

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


More information about the wp-trac mailing list