diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index 12c532628f..bc205894c6 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -1593,7 +1593,7 @@ class WP_Query { $qv['monthnum'] = absint($qv['monthnum']); $qv['day'] = absint($qv['day']); $qv['w'] = absint($qv['w']); - $qv['m'] = preg_replace( '|[^0-9]|', '', $qv['m'] ); + $qv['m'] = is_scalar( $qv['m'] ) ? preg_replace( '|[^0-9]|', '', $qv['m'] ) : ''; $qv['paged'] = absint($qv['paged']); $qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // comma separated list of positive or negative integers $qv['author'] = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // comma separated list of positive or negative integers diff --git a/tests/phpunit/tests/query/date.php b/tests/phpunit/tests/query/date.php index 9af9655bdc..ed5231b2c6 100644 --- a/tests/phpunit/tests/query/date.php +++ b/tests/phpunit/tests/query/date.php @@ -258,6 +258,18 @@ class Tests_Query_Date extends WP_UnitTestCase { $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) ); } + /** + * @ticket 36718 + */ + public function test_non_scalar_m_should_be_discarded() { + $expected = $this->_get_query_result( ); + $posts = $this->_get_query_result( array( + 'm' => array( '1234' ), // ignored + ) ); + + $this->assertEquals( $expected, $posts ); + } + public function test_simple_monthnum_expecting_results() { $posts = $this->_get_query_result( array( 'monthnum' => 5,