diff --git src/wp-includes/date.php src/wp-includes/date.php
index 0c42766..7b73a3e 100644
|
|
|
class WP_Date_Query { |
| 235 | 235 | |
| 236 | 236 | $compare = $this->get_compare( $query ); |
| 237 | 237 | |
| | 238 | $inclusive = ! empty( $query['inclusive'] ); |
| | 239 | |
| 238 | 240 | $lt = '<'; |
| 239 | 241 | $gt = '>'; |
| 240 | | if ( ! empty( $query['inclusive'] ) ) { |
| | 242 | if ( $inclusive ) { |
| 241 | 243 | $lt .= '='; |
| 242 | 244 | $gt .= '='; |
| 243 | 245 | } |
| 244 | 246 | |
| 245 | 247 | // Range queries |
| 246 | 248 | if ( ! empty( $query['after'] ) ) |
| 247 | | $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], true ) ); |
| | 249 | $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) ); |
| 248 | 250 | |
| 249 | 251 | if ( ! empty( $query['before'] ) ) |
| 250 | | $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], false ) ); |
| | 252 | $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) ); |
| 251 | 253 | |
| 252 | 254 | // Specific value queries |
| 253 | 255 | |
diff --git tests/phpunit/tests/query/dateQuery.php tests/phpunit/tests/query/dateQuery.php
index 47cc71d..d737d60 100644
|
|
|
class Tests_Query_DateQuery extends WP_UnitTestCase { |
| 254 | 254 | $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) ); |
| 255 | 255 | } |
| 256 | 256 | |
| | 257 | public function test_date_query_inclusive_between_dates() { |
| | 258 | $posts = $this->_get_query_result( array( |
| | 259 | 'date_query' => array( |
| | 260 | 'after' => array( |
| | 261 | 'year' => 2007, |
| | 262 | 'month' => 1 |
| | 263 | ), |
| | 264 | 'before' => array( |
| | 265 | 'year' => 2008, |
| | 266 | 'month' => 12 |
| | 267 | ), |
| | 268 | 'inclusive' => true |
| | 269 | ), |
| | 270 | ) ); |
| | 271 | |
| | 272 | |
| | 273 | $expected_dates = array( |
| | 274 | '2007-01-22 03:49:21', |
| | 275 | '2007-05-16 17:32:22', |
| | 276 | '2007-09-24 07:17:23', |
| | 277 | '2008-03-29 09:04:25', |
| | 278 | '2008-07-15 11:32:26', |
| | 279 | '2008-12-10 13:06:27', |
| | 280 | ); |
| | 281 | |
| | 282 | $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) ); |
| | 283 | } |
| | 284 | |
| 257 | 285 | public function test_date_query_year_expecting_results() { |
| 258 | 286 | $posts = $this->_get_query_result( array( |
| 259 | 287 | 'date_query' => array( |