mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-04 17:20:07 +00:00
Query: Allow the hyphen-prefix-for-search-exclusion feature to be disabled by filter.
WordPress 4.4 introduced "hyphen exclusion" for search terms, so that "foo -bar" would return posts containing "foo" AND not containing "bar". The new filter 'wp_query_use_hyphen_for_exclusion' allows developers to disable this feature when it's known that their content will contain semantically important leading hyphens. Props chriseverson, choongsavvii. Fixes #38099. git-svn-id: https://develop.svn.wordpress.org/trunk@38792 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -59,6 +59,28 @@ class Tests_Query_Search extends WP_UnitTestCase {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38099
|
||||
*/
|
||||
function test_filter_wp_query_use_hyphen_for_exclusion() {
|
||||
$title = '-HYPHENATION_TEST';
|
||||
|
||||
// Create a post with a title which starts with a hyphen
|
||||
$post_id = self::factory()->post->create( array(
|
||||
'post_content' => $title, 'post_type' => $this->post_type
|
||||
) );
|
||||
|
||||
// By default, we can use the hyphen prefix to exclude results
|
||||
$this->assertEquals( array(), $this->get_search_results( $title ) );
|
||||
|
||||
// After we disable the feature using the filter, we should get the result
|
||||
add_filter( 'wp_query_use_hyphen_for_exclusion', '__return_false' );
|
||||
$result = $this->get_search_results( $title );
|
||||
$post = array_pop( $result );
|
||||
$this->assertEquals( $post->ID, $post_id );
|
||||
remove_filter( 'wp_query_use_hyphen_for_exclusion', '__return_false' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33988
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user