diff --git src/wp-includes/query.php src/wp-includes/query.php
index d53ec42..3703428 100644
|
|
class WP_Query { |
2268 | 2268 | $like = '%' . $wpdb->esc_like( $q['s'] ) . '%'; |
2269 | 2269 | } |
2270 | 2270 | |
2271 | | $search_orderby = '(CASE '; |
| 2271 | $search_orderby = ''; |
2272 | 2272 | |
2273 | 2273 | // sentence match in 'post_title' |
2274 | 2274 | if ( $like ) { |
… |
… |
class WP_Query { |
2289 | 2289 | if ( $like ) { |
2290 | 2290 | $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 4 ", $like ); |
2291 | 2291 | } |
2292 | | $search_orderby .= 'ELSE 5 END)'; |
| 2292 | |
| 2293 | if ( $search_orderby ) { |
| 2294 | $search_orderby = '(CASE ' . $search_orderby . 'ELSE 5 END)'; |
| 2295 | } |
2293 | 2296 | } else { |
2294 | 2297 | // single word or sentence search |
2295 | 2298 | $search_orderby = reset( $q['search_orderby_title'] ) . ' DESC'; |
diff --git tests/phpunit/tests/query/search.php tests/phpunit/tests/query/search.php
index caf862c..5fe6d5e 100644
|
|
class Tests_Query_Search extends WP_UnitTestCase { |
125 | 125 | |
126 | 126 | $this->assertEqualSets( array( $p3 ), $q->posts ); |
127 | 127 | } |
| 128 | |
| 129 | /** |
| 130 | * @ticket 35361 |
| 131 | */ |
| 132 | public function test_search_orderby_should_be_empty_when_search_string_is_longer_than_6_words_and_exclusion_operator_is_used() { |
| 133 | $q = new WP_Query( array( |
| 134 | 's' => 'foo1 foo2 foo3 foo4 foo5 foo6 foo7 -bar', |
| 135 | 'fields' => 'ids', |
| 136 | ) ); |
| 137 | |
| 138 | $this->assertNotRegExp( '|ORDER BY \(CASE[^\)]+\)|', $q->request ); |
| 139 | } |
128 | 140 | } |