[wp-trac] [WordPress Trac] #29822: Support complex queries in WP_Date_Query

WordPress Trac noreply at wordpress.org
Tue Oct 14 18:32:14 UTC 2014


#29822: Support complex queries in WP_Date_Query
--------------------------+---------------------------
 Reporter:  boonebgorges  |       Owner:  boonebgorges
     Type:  enhancement   |      Status:  accepted
 Priority:  normal        |   Milestone:  4.1
Component:  Query         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+---------------------------
Changes (by boonebgorges):

 * component:  Date/Time => Query


Comment:

 [attachment: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.

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


More information about the wp-trac mailing list