[wp-trac] [WordPress Trac] #29823: WP_Date_Query across tables

WordPress Trac noreply at wordpress.org
Sun Oct 19 19:15:21 UTC 2014


#29823: WP_Date_Query across tables
--------------------------+-----------------------------
 Reporter:  boonebgorges  |       Owner:  boonebgorges
     Type:  enhancement   |      Status:  accepted
 Priority:  normal        |   Milestone:  Future Release
Component:  Query         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:
--------------------------+-----------------------------
Changes (by boonebgorges):

 * keywords:   => needs-patch
 * component:  Date/Time => Query


Comment:

 A quick note that the changes in [29933] make this sorta possible. So to
 use my example above:

 >  Things like: all posts from 2011 that have comments from 2013 or later.

 This translates to:

 {{{
 'date_query' => array(
     'relation' => 'AND',
     array(
         'column' => $wpdb->posts . '.post_date',
         'year' => 2011,
     ),
     array(
         'column' => $wpdb->comments . '.comment_date',
         'after' => '2013-01-01 00:00:00',
     ),
 ),
 }}}

 This ought to generate the correct WHERE clause. However, it doesn't build
 the JOIN clauses for you, so you'd have to do some other filtering to make
 it really work. Unfortunately, `WP_Date_Query::get_sql()` returns a string
 rather than an array of 'join' and 'where' strings like the other query
 classes, and we can't change that for backward compatibility. But maybe in
 a future version we can introduce another param to `get_sql()` that will
 change the return value format, and we can make all core calls to
 `get_sql()` use that param, so that this kind of use will be supported in
 `WP_Query` and `WP_Comment_Query`.

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


More information about the wp-trac mailing list