diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index b4aae270b2..765dfcc743 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -2231,8 +2231,8 @@ class WP_Query { else $term = trim( $term, "\"' " ); - // Avoid single A-Z. - if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z]$/i', $term ) ) ) + // Avoid single A-Z and single dashes. + if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z\-]$/i', $term ) ) ) continue; if ( in_array( call_user_func( $strtolower, $term ), $stopwords, true ) ) diff --git a/tests/phpunit/tests/query/search.php b/tests/phpunit/tests/query/search.php index 5fe6d5e62a..45ec8053ce 100644 --- a/tests/phpunit/tests/query/search.php +++ b/tests/phpunit/tests/query/search.php @@ -126,6 +126,31 @@ class Tests_Query_Search extends WP_UnitTestCase { $this->assertEqualSets( array( $p3 ), $q->posts ); } + /** + * @ticket 36195 + */ + public function test_s_should_not_exclude_for_dashes_between_words() { + $p1 = self::factory()->post->create( array( + 'post_status' => 'publish', + 'post_content' => 'This post has foo but also bar', + ) ); + $p2 = self::factory()->post->create( array( + 'post_status' => 'publish', + 'post_content' => 'This post has only bar', + ) ); + $p3 = self::factory()->post->create( array( + 'post_status' => 'publish', + 'post_content' => 'This post has only foo - bar', + ) ); + + $q = new WP_Query( array( + 's' => 'foo - bar', + 'fields' => 'ids', + ) ); + + $this->assertEqualSets( array( $p1, $p3 ), $q->posts ); + } + /** * @ticket 35361 */