/**
* Constructor.
*
+ * @since 3.7.0
+ * @since 4.0.0 The $inclusive logic was updated to include all times within the date range.
+ *
* @param array $date_query {
* One or more associative arrays of date query parameters.
*
* @type string $day Optional when passing array.The day of the month.
* Default (string:empty)|(array:1). Accepts numbers 1-31.
* }
- * @type string|array $after Optional. Date to retrieve posts before. Accepts strtotime()-compatible
+ * @type string|array $after Optional. Date to retrieve posts after. Accepts strtotime()-compatible
* string, or array of 'year', 'month', 'day' values. {
*
* @type string $year The four-digit year. Default empty. Accepts any four-digit year.
* Default (string:empty)|(array:last day of month). Accepts numbers 1-31.
* }
* @type string $column Optional. Used to add a clause comparing a column other than the column
- * specified in the top-level $column paramater. Default is the value
+ * specified in the top-level $column parameter. Default is the value
* of top-level $column. Accepts 'post_date', 'post_date_gmt',
* 'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt'.
* @type string $compare Optional. The comparison operator. Default '='. Accepts '=', '!=',
* '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
* @type bool $inclusive Optional. Include results from dates specified in 'before' or 'after'.
* Default. Accepts.
- * @type int $year Optional. The four-digit near number. Default empty. Accepts any
+ * @type int $year Optional. The four-digit year number. Default empty. Accepts any
* four-digit year.
* @type int $month Optional. The two-digit month number. Default empty. Accepts numbers 1-12.
* @type int $week Optional. The week number of the year. Default empty. Accepts numbers 0-53.
+ * @type int $dayofyear Optional. The day number of the year. Default empty. Accepts numbers 1-366.
* @type int $day Optional. The day of the month. Default empty. Accepts numbers 1-31.
+ * @type int $dayofweek Optional. The day number of the week. Default empty. Accepts numbers 1-7.
* @type int $hour Optional. The hour of the day. Default empty. Accepts numbers 0-23.
* @type int $minute Optional. The minute of the hour. Default empty. Accepts numbers 0-60.
* @type int $second Optional. The second of the minute. Default empty. Accepts numbers 0-60.
* Accepts 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt',
* 'comment_date', 'comment_date_gmt'.
*/
- function __construct( $date_query, $default_column = 'post_date' ) {
+ public function __construct( $date_query, $default_column = 'post_date' ) {
if ( empty( $date_query ) || ! is_array( $date_query ) )
return;
$compare = $this->get_compare( $query );
+ $inclusive = ! empty( $query['inclusive'] );
+
+ // Assign greater- and less-than values.
$lt = '<';
$gt = '>';
- if ( ! empty( $query['inclusive'] ) ) {
+
+ if ( $inclusive ) {
$lt .= '=';
$gt .= '=';
}
// Range queries
if ( ! empty( $query['after'] ) )
- $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], true ) );
+ $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );
if ( ! empty( $query['before'] ) )
- $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], false ) );
+ $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );
// Specific value queries
if ( isset( $query['month'] ) && $value = $this->build_value( $compare, $query['month'] ) )
$where_parts[] = "MONTH( $column ) $compare $value";
-
- // Legacy
- if ( isset( $query['monthnum'] ) && $value = $this->build_value( $compare, $query['monthnum'] ) )
+ else if ( isset( $query['monthnum'] ) && $value = $this->build_value( $compare, $query['monthnum'] ) )
$where_parts[] = "MONTH( $column ) $compare $value";
if ( isset( $query['week'] ) && false !== ( $value = $this->build_value( $compare, $query['week'] ) ) )
$where_parts[] = _wp_mysql_week( $column ) . " $compare $value";
-
- // Legacy
- if ( isset( $query['w'] ) && false !== ( $value = $this->build_value( $compare, $query['w'] ) ) )
+ else if ( isset( $query['w'] ) && false !== ( $value = $this->build_value( $compare, $query['w'] ) ) )
$where_parts[] = _wp_mysql_week( $column ) . " $compare $value";
if ( isset( $query['dayofyear'] ) && $value = $this->build_value( $compare, $query['dayofyear'] ) )