diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index 3703428d95..44e9a5c242 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -2775,7 +2775,7 @@ class WP_Query { } // If a search pattern is specified, load the posts that match. - if ( ! empty( $q['s'] ) ) { + if ( strlen( $q['s'] ) ) { $search = $this->parse_search( $q ); } diff --git a/tests/phpunit/tests/query/search.php b/tests/phpunit/tests/query/search.php index 5fe6d5e62a..c21787d090 100644 --- a/tests/phpunit/tests/query/search.php +++ b/tests/phpunit/tests/query/search.php @@ -137,4 +137,26 @@ class Tests_Query_Search extends WP_UnitTestCase { $this->assertNotRegExp( '|ORDER BY \(CASE[^\)]+\)|', $q->request ); } + + /** + * @ticket 31025 + */ + public function test_s_zero() { + $p1 = $this->factory->post->create( array( + 'post_status' => 'publish', + 'post_title' => '1', + ) ); + + $p2 = $this->factory->post->create( array( + 'post_status' => 'publish', + 'post_title' => '0', + ) ); + + $q = new WP_Query( array( + 's' => '0', + 'fields' => 'ids', + ) ); + + $this->assertEqualSets( array( $p2 ), $q->posts ); + } }