Make WordPress Core

Opened 5 years ago

Last modified 8 weeks ago

#29823 reopened enhancement

WP_Date_Query across tables

Reported by: boonebgorges Owned by: boonebgorges
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Query Keywords: needs-patch, bulk-reopened
Focuses: Cc:


The changes proposed in #29822 will make it possible to think about cross-table date queries. Things like: all posts from 2011 that have comments from 2013 or later.

Using this ticket as a placeholder for ideas regarding syntax (do we allow table names to be passed as a param? or perhaps a 'type' argument like WP_Meta_Query has, which is then translated into table names?) and other discussion.

Change History (6)

#1 @boonebgorges
5 years ago

  • Owner set to boonebgorges
  • Status changed from new to accepted

This ticket was mentioned in IRC in #wordpress-dev by boonebgorges. ​View the logs.

5 years ago

#3 @boonebgorges
5 years ago

  • Component changed from Date/Time to Query
  • Keywords needs-patch added

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',
        'column' => $wpdb->posts . '.post_date',
        'year' => 2011,
        '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.

#4 @chriscct7
3 years ago

I like the idea of this

#5 @iseulde
4 months ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from accepted to closed

This ticket has not seen any activity in over *two* years, so I'm closing it as "wontfix".

The ticket may lack decisiveness, may have become irrelevant, or may not have gathered enough interest.

If you think this ticket does deserve some attention again, feel free to reopen.

For bugs, it would be great if you could provide updated steps to reproduce against the latest version of WordPress (5.0.2 at the time of writing). Remember images or a video can be superior to explain a problem. At the very least, quickly test again to make sure the bug still exists.

If it’s an enhancement or feature, some extra motivation may help.

Thank you for your contributions to WordPress! <3

#6 @JeffPaul
8 weeks ago

  • Keywords bulk-reopened added
  • Milestone set to Awaiting Review
  • Resolution wontfix deleted
  • Status changed from closed to reopened

A ​decision was made to reopen tickets that were closed in the bulk edit that this ticket was affected by. This ticket is being placed back into the Awaiting Review milestone so it can be individually evaluated and verified to determine if it is still relevant/valid or reproducible.

Note: See TracTickets for help on using tickets.