Meta, Date, and Tax Query improvements in WP 4.1

For WP 4.1, I’ll be working on improvements to WP_Meta_Query, WP_Tax_Query, and WP_Date_Query, the Three Tenors Three Stooges Three Amigos of WordPress. Here’s a summary of the proposed changes, with some notes about where help is needed.

Unit test coverage

Test coverage for these three classes has historically been pretty spotty, but is absolutely critical for any meaningful refactoring to take place. I’ve meticulously picked over them and created a set of comprehensive tests for each one (#29560, #29718, #29781). Coverage is now quite good, but more eyes are always welcome.

Multi-relational and nested queries

All three classes currently accept a ‘relation’ parameter, which allows multiple query clauses to be joined with AND or OR. So, for instance, you can query for: posts that are in the ‘Boone’ category AND have the tag ‘Awesome’ AND do not have the term ‘Raphael’ in the favorite_turtle taxonomy. But this syntax only allows for so much expressiveness: you can’t mix AND and OR, and you can’t group clauses. These limitations make it difficult to use these queries in support of complex content filtering – like you might need, say, if you’re using WordPress to power the inventory system for an online store.

For 4.1, I’ll be working on allowing the necessary syntax for multi-relation queries that can be grouped and nested to an arbitrary depth. See the following tickets for patches and discussion:

Much of the infrastructure that will support the new syntax will be shared between the classes. If you’re familiar with current WP_*_Query internals, you may want to check out the patches and join the discussion at the WP_Meta_Query ticket, which is the furthest along of the three classes in this refactoring process.

Miscellania

Once the changes discussed above are in place, there are a number of smaller but equally lovely improvements I’d like to begin addressing:

  • #29181 ‘EXISTS’ and ‘NOT EXISTS’ operators for WP_Tax_Query
  • #29823 WP_Date_Query across tables
  • #24093 Improve WP_Meta_Query performance by switching to subqueries rather than table joins. This is one where we could use lots of testing; if you know how to set up a VM with an old version of MySQL, then your help would be appreciated.

Do you have other ideas for how these three classes could be improved in 4.1 and beyond?

#4-1