[wp-trac] [WordPress Trac] #18694: Improved date arguments for WP_Query
WordPress Trac
wp-trac at lists.automattic.com
Sat Jul 21 07:14:22 UTC 2012
#18694: Improved date arguments for WP_Query
-------------------------------------+------------------------------
Reporter: Viper007Bond | Owner: viper007bond
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.3
Severity: normal | Resolution:
Keywords: has-patch needs-testing |
-------------------------------------+------------------------------
Changes (by Viper007Bond):
* keywords: has-patch => has-patch needs-testing
Comment:
I believe the above patch is ready to go into core.
It adds support for querying both posts and comments based on date
parameters:
{{{
$query = new WP_Query( array(
'date_query' => array(
'column' => 'optional, column to query against, default is
post_date',
'compare' => 'optional, see WP_Date_Query::get_compare()',
'relation' => 'optional, OR or AND, how the sub-arrays
should be compared, default is AND',
array(
'column' => 'see above',
'compare' => 'see above',
'after' => 'string or array, see
WP_Date_Query::build_mysql_datetime()',
'before' => 'string or array, see
WP_Date_Query::build_mysql_datetime()',
'inclusive' => 'boolean, for after/before, whether
exact value should be matched or not',
'year' => '4 digit int',
'month' => 'int, 1-12',
'week' => 'int, 0-53',
'day' => 'int, 1-31',
'hour' => 'int, 0-23',
'minute' => 'int, 0-60',
'second' => 'int, 0-60',
),
),
) );
}}}
{{{
$comments = get_comments( array(
'date_query' => array(
// ...
),
) );
}}}
Not supported is querying against post meta values however the class is
specifically written to be able to query against any database table or
column. `WP_Meta_Query` just needs to be updated to use this new class and
I wasn't sure the best way to go about doing that argument wise.
Legacy date/time parameters are handed by this new class and it's
important that testing be done to make sure that queries function the same
way as before.
Please apply the patch, test, and post your feedback! :)
Incoming test file next.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/18694#comment:37>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list