Changeset 38792
- Timestamp:
- 10/14/2016 08:05:40 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-query.php
r38768 r38792 722 722 * @type string $s Search keyword(s). Prepending a term with a hyphen will 723 723 * exclude posts matching that term. Eg, 'pillow -sofa' will 724 * return posts containing 'pillow' but not 'sofa'. 724 * return posts containing 'pillow' but not 'sofa'. This feature 725 * can be disabled using the 726 * 'wp_query_use_hyphen_for_exclusion' filter. 725 727 * @type int $second Second of the minute. Default empty. Accepts numbers 0-60. 726 728 * @type bool $sentence Whether to search by phrase. Default false. … … 1319 1321 $searchand = ''; 1320 1322 $q['search_orderby_title'] = array(); 1323 1324 /** 1325 * Filters whether search terms preceded by hyphens should excluded from results. 1326 * 1327 * @since 4.7.0 1328 * 1329 * @param bool Whether the query should exclude terms preceded with a hyphen. 1330 */ 1331 $hyphen_exclusion = apply_filters( 'wp_query_use_hyphen_for_exclusion', true ); 1332 1321 1333 foreach ( $q['search_terms'] as $term ) { 1322 1334 // Terms prefixed with '-' should be excluded. 1323 1335 $include = '-' !== substr( $term, 0, 1 ); 1324 if ( $include ) {1336 if ( $include || ! $hyphen_exclusion ) { 1325 1337 $like_op = 'LIKE'; 1326 1338 $andor_op = 'OR'; -
trunk/tests/phpunit/tests/query/search.php
r38733 r38792 58 58 function filter_wp_search_stopwords() { 59 59 return array(); 60 } 61 62 /** 63 * @ticket 38099 64 */ 65 function test_filter_wp_query_use_hyphen_for_exclusion() { 66 $title = '-HYPHENATION_TEST'; 67 68 // Create a post with a title which starts with a hyphen 69 $post_id = self::factory()->post->create( array( 70 'post_content' => $title, 'post_type' => $this->post_type 71 ) ); 72 73 // By default, we can use the hyphen prefix to exclude results 74 $this->assertEquals( array(), $this->get_search_results( $title ) ); 75 76 // After we disable the feature using the filter, we should get the result 77 add_filter( 'wp_query_use_hyphen_for_exclusion', '__return_false' ); 78 $result = $this->get_search_results( $title ); 79 $post = array_pop( $result ); 80 $this->assertEquals( $post->ID, $post_id ); 81 remove_filter( 'wp_query_use_hyphen_for_exclusion', '__return_false' ); 60 82 } 61 83
Note: See TracChangeset
for help on using the changeset viewer.