Ticket #21688: 21688-2.patch
| File 21688-2.patch, 1.8 KB (added by azaozz, 9 months ago) |
|---|
-
wp-includes/query.php
2174 2174 } 2175 2175 2176 2176 // If a search pattern is specified, load the posts that match 2177 if ( !empty($q['s']) ) { 2177 // Sanity check: search string shouldn't be more than 1600 characters 2178 // (some browsers won't send more than 2000 characters incl. the URL in a urlencoded GET request). 2179 if ( !empty($q['s']) && strlen($q['s']) < 1600 ) { 2178 2180 // added slashes screw with quote grouping when done early, so done later 2179 2181 $q['s'] = stripslashes($q['s']); 2180 2182 if ( empty( $_GET['s'] ) && $this->is_main_query() ) … … 2183 2185 $q['search_terms'] = array($q['s']); 2184 2186 } else { 2185 2187 preg_match_all('/".*?("|$)|((?<=[\r\n\t ",+])|^)[^\r\n\t ",+]+/', $q['s'], $matches); 2186 $q['search_terms'] = array_map('_search_terms_tidy', $matches[0]); 2188 $q['_search_terms'] = array_map('_search_terms_tidy', $matches[0]); 2189 $q['search_terms'] = array(); 2190 2191 foreach ( (array) $q['_search_terms'] as $term ) { 2192 if ( empty($term) || strlen($term) < 3 ) 2193 continue; 2194 $q['search_terms'][] = $term; 2195 } 2196 2197 unset($q['_search_terms']); 2198 // if the search string has only short terms or more than 10 terms match it as sentence 2199 if ( empty($q['search_terms']) || count($q['search_terms']) > 10 ) 2200 $q['search_terms'] = array($q['s']); 2187 2201 } 2202 2188 2203 $n = !empty($q['exact']) ? '' : '%'; 2189 2204 $searchand = ''; 2190 foreach( (array)$q['search_terms'] as $term ) {2205 foreach( $q['search_terms'] as $term ) { 2191 2206 $term = esc_sql( like_escape( $term ) ); 2192 2207 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))"; 2193 2208 $searchand = ' AND ';
