In `WP_Date_Query::get_sql_for_subquery()`, don't parse duplicate parameters - only parse one of `w` and `week` or `month` and `monthnum`.
Adds unit tests. Props oso96_2000, ChriCo. Fixes #25835. git-svn-id: https://develop.svn.wordpress.org/trunk@28252 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
61765b8efd
commit
89ecbcc7cb
|
@ -256,16 +256,12 @@ class WP_Date_Query {
|
|||
|
||||
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'] ) )
|
||||
|
|
|
@ -555,4 +555,49 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
|
|||
|
||||
$this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
|
||||
}
|
||||
|
||||
public function test_date_params_monthnum_m_duplicate() {
|
||||
$posts = $this->_get_query_result( array(
|
||||
'date_query' => array(
|
||||
'month' => 5,
|
||||
'monthnum' => 9
|
||||
),
|
||||
) );
|
||||
|
||||
$expected_dates = array(
|
||||
'1972-05-24 14:53:45',
|
||||
'2003-05-27 22:45:07',
|
||||
'2004-05-22 12:34:12',
|
||||
'2007-05-16 17:32:22',
|
||||
'2025-05-20 10:13:01',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
|
||||
|
||||
$this->assertContains( "AND ( ( MONTH( post_date ) = 5 ) ) AND", $this->q->request );
|
||||
|
||||
$this->assertNotContains( "AND ( ( MONTH( post_date ) = 5 AND MONTH( post_date ) = 9 ) ) AND", $this->q->request );
|
||||
}
|
||||
|
||||
public function test_date_params_week_w_duplicate() {
|
||||
$posts = $this->_get_query_result( array(
|
||||
'date_query' => array(
|
||||
'week' => 21,
|
||||
'w' => 22
|
||||
),
|
||||
) );
|
||||
|
||||
$expected_dates = array(
|
||||
'1972-05-24 14:53:45',
|
||||
'2004-05-22 12:34:12',
|
||||
'2025-05-20 10:13:01',
|
||||
);
|
||||
|
||||
|
||||
$this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
|
||||
|
||||
$this->assertContains( "AND ( ( WEEK( post_date, 1 ) = 21 ) ) AND", $this->q->request );
|
||||
|
||||
$this->assertNotContains( "AND ( ( WEEK( post_date, 1 ) = 21 AND WEEK( post_date, 1 ) = 22 ) ) AND", $this->q->request );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue