#29822 closed enhancement (fixed)
Support complex queries in WP_Date_Query
Reported by: | boonebgorges | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Query | Keywords: | has-patch |
Focuses: | Cc: |
Description
Sister tickets: #29642 (WP_Meta_Query
) and #29738 (WP_Tax_Query
).
WP_Date_Query
currently supports one level of relation between subqueries, so you can ask for something like 'items from 2011 OR items from 2010' or 'items published in 2010 AND on a Thursday'. But, excepting some clever manipulation of IN
clauses, it's not possible to get any more complex than this.
I propose to update WP_Date_Query
to support arbitrarily nested queries, which will support mixed relations.
Using the WP_Recursive_Query
structure in #29642 will automatically mean another added feature: the ability to construct a date query across multiple columns. So you'll be able to make a request like 'items with post_date between 2010 and 2012 AND post_modified > 2013'. Cross-table support will be the next logical step but is a bit complex to include in this ticket; I'll open a separate one for that feature.
See #29781 for the unit tests that will support this refactoring.
I'll have an initial patch for review within a couple days.
Attachments (2)
Change History (8)
This ticket was mentioned in IRC in #wordpress-dev by boonebgorges. View the logs.
10 years ago
#2
@
10 years ago
- Keywords has-patch added
- Owner set to boonebgorges
- Status changed from new to accepted
#3
@
10 years ago
- Component changed from Date/Time to Query
29822.2.patch brings WP_Date_Query
up to snuff with WP_Meta_Query
[29887] and WP_Tax_Query
[29891]. Documentation, method naming and order, etc is all aligned. Posting here for review.
My original description for this ticket is a bit lacking, so I want to take a moment to spell out what these changes will (and won't) mean in terms of WP_Date_Query
syntax. Because posts generally only have a single date, it's not immediately obvious why you'd want to do this sort of query in real life. Here's an example:
// All items from 2012 that were created outside of work hours // (either on a weekend or between 5pm and midnight) 'date_query' => array( 'relation' => 'AND', array( 'column' => 'post_date', 'year' => 2012, ), array( 'relation' => 'OR', 'column' => 'post_date', array( 'dayofweek' => array( 1, 7 ), ), array( 'hour' => 17, 'compare' => '>=', ), ), ),
This will get significantly more powerful once it's possible to build date queries across tables. See #29823, #25775.
29822.patch implements the proposed
WP_Recursive_Query
described here: https://core.trac.wordpress.org/ticket/29642#comment:6