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

WordPress Trac noreply at wordpress.org
Mon Jan 26 18:58:39 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:  needs-patch needs-unit-tests  |     Focuses:
------------------------------------------+-----------------------------

Comment (by boonebgorges):

 Replying to [comment:7 Funkatronic]:
 > My idea to change `parse_orderby`:
 > - Get all aliases, both custom and ones created by `WP_Meta_query`, in
 query
 > - Check if `orderby` matches any of the aliases
 > - If it matches, create an `ORDER BY` clause that uses that alias:
 `alias.meta_value`
 >
 > You don't have to know what the related join clauses contain, just as
 long as you know the alias thats being used for the join, you can use it
 for the `ORDER BY`, at least imho.

 This all sounds good to me. You're probably right about not needing to
 know what the alias is associated with. I'd need to see the unit tests :)

 >
 > As far as I can tell, `table_aliases` keeps track of all the aliases
 used, though like you said, we need to test to make sure we cover all
 bases.  Also, does WP have any sanitation functions for table aliases?

 Use `sanitize_key()`. It's not specific to table aliases or even to MySQL,
 but it's the most restrictive of our sanitizers, and it's what
 `register_post_type()` uses for post type strings, etc.

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


More information about the wp-trac mailing list