diff --git src/wp-includes/date.php src/wp-includes/date.php
index 0c42766..ed8fff7 100644
|
|
class WP_Date_Query { |
256 | 256 | |
257 | 257 | if ( isset( $query['month'] ) && $value = $this->build_value( $compare, $query['month'] ) ) |
258 | 258 | $where_parts[] = "MONTH( $column ) $compare $value"; |
259 | | |
260 | | // Legacy |
261 | | if ( isset( $query['monthnum'] ) && $value = $this->build_value( $compare, $query['monthnum'] ) ) |
| 259 | else if ( isset( $query['monthnum'] ) && $value = $this->build_value( $compare, $query['monthnum'] ) ) |
262 | 260 | $where_parts[] = "MONTH( $column ) $compare $value"; |
263 | 261 | |
264 | 262 | if ( isset( $query['week'] ) && false !== ( $value = $this->build_value( $compare, $query['week'] ) ) ) |
265 | 263 | $where_parts[] = _wp_mysql_week( $column ) . " $compare $value"; |
266 | | |
267 | | // Legacy |
268 | | if ( isset( $query['w'] ) && false !== ( $value = $this->build_value( $compare, $query['w'] ) ) ) |
| 264 | else if ( isset( $query['w'] ) && false !== ( $value = $this->build_value( $compare, $query['w'] ) ) ) |
269 | 265 | $where_parts[] = _wp_mysql_week( $column ) . " $compare $value"; |
270 | 266 | |
271 | 267 | if ( isset( $query['dayofyear'] ) && $value = $this->build_value( $compare, $query['dayofyear'] ) ) |
diff --git tests/phpunit/tests/query/dateQuery.php tests/phpunit/tests/query/dateQuery.php
index 47cc71d..5e456e5 100644
|
|
class Tests_Query_DateQuery extends WP_UnitTestCase { |
555 | 555 | |
556 | 556 | $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) ); |
557 | 557 | } |
| 558 | |
| 559 | public function test_date_params_monthnum_m_duplicate() { |
| 560 | $posts = $this->_get_query_result( array( |
| 561 | 'date_query' => array( |
| 562 | 'month' => 5, |
| 563 | 'monthnum' => 9 |
| 564 | ), |
| 565 | ) ); |
| 566 | |
| 567 | $expected_dates = array( |
| 568 | '1972-05-24 14:53:45', |
| 569 | '2003-05-27 22:45:07', |
| 570 | '2004-05-22 12:34:12', |
| 571 | '2007-05-16 17:32:22', |
| 572 | '2025-05-20 10:13:01', |
| 573 | ); |
| 574 | |
| 575 | $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) ); |
| 576 | |
| 577 | $this->assertContains( "AND ( ( MONTH( post_date ) = 5 ) ) AND", $this->q->request ); |
| 578 | |
| 579 | $this->assertNotContains( "AND ( ( MONTH( post_date ) = 5 AND MONTH( post_date ) = 9 ) ) AND", $this->q->request ); |
| 580 | } |
| 581 | |
| 582 | public function test_date_params_week_w_duplicate() { |
| 583 | $posts = $this->_get_query_result( array( |
| 584 | 'date_query' => array( |
| 585 | 'week' => 21, |
| 586 | 'w' => 22 |
| 587 | ), |
| 588 | ) ); |
| 589 | |
| 590 | $expected_dates = array( |
| 591 | '1972-05-24 14:53:45', |
| 592 | '2004-05-22 12:34:12', |
| 593 | '2025-05-20 10:13:01', |
| 594 | ); |
| 595 | |
| 596 | |
| 597 | $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) ); |
| 598 | |
| 599 | $this->assertContains( "AND ( ( WEEK( post_date, 1 ) = 21 ) ) AND", $this->q->request ); |
| 600 | |
| 601 | $this->assertNotContains( "AND ( ( WEEK( post_date, 1 ) = 21 AND WEEK( post_date, 1 ) = 22 ) ) AND", $this->q->request ); |
| 602 | } |
558 | 603 | } |
| 604 | No newline at end of file |