Query: Ignore search terms consisting of a single dash.
Due to the "exclude" support added in WP 4.4, single dashes were being converted to "NOT LIKE '%%'" clauses, causing all searches to fail. Props RomSocial, swissspidy. Fixes #36195. git-svn-id: https://develop.svn.wordpress.org/trunk@36989 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0fdf0d4566
commit
9f05bf8ed9
@ -2194,8 +2194,8 @@ class WP_Query {
|
|||||||
else
|
else
|
||||||
$term = trim( $term, "\"' " );
|
$term = trim( $term, "\"' " );
|
||||||
|
|
||||||
// Avoid single A-Z.
|
// Avoid single A-Z and single dashes.
|
||||||
if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z]$/i', $term ) ) )
|
if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z\-]$/i', $term ) ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( in_array( call_user_func( $strtolower, $term ), $stopwords, true ) )
|
if ( in_array( call_user_func( $strtolower, $term ), $stopwords, true ) )
|
||||||
|
@ -126,6 +126,31 @@ class Tests_Query_Search extends WP_UnitTestCase {
|
|||||||
$this->assertEqualSets( array( $p3 ), $q->posts );
|
$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
|
* @ticket 35361
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user