Changeset 34934 for trunk/src/wp-includes/query.php
- Timestamp:
- 10/08/2015 03:17:22 AM (10 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/query.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r34903 r34934 1510 1510 * @since 4.2.0 Introduced the ability to order by specific clauses of a `$meta_query`, by passing the clause's 1511 1511 * array key to `$orderby`. 1512 * @since 4.4.0 Introduced `$post_name__in` and `$title` parameters. 1512 * @since 4.4.0 Introduced `$post_name__in` and `$title` parameters. `$s` was updated to support excluded 1513 * search terms, by prepending a hyphen. 1513 1514 * @access public 1514 1515 * … … 1588 1589 * 'posts_per_page' when is_archive(), or is_search() are true. 1589 1590 * @type array $post_name__in An array of post slugs that results must match. 1590 * @type string $s Search keyword. 1591 * @type string $s Search keyword(s). Prepending a term with a hyphen will 1592 * exclude posts matching that term. Eg, 'pillow -sofa' will 1593 * return posts containing 'pillow' but not 'sofa'. 1591 1594 * @type int $second Second of the minute. Default empty. Accepts numbers 0-60. 1592 1595 * @type bool $sentence Whether to search by phrase. Default false. … … 2159 2162 $q['search_orderby_title'] = array(); 2160 2163 foreach ( $q['search_terms'] as $term ) { 2161 if ( $n ) { 2164 // Terms prefixed with '-' should be excluded. 2165 $include = '-' !== substr( $term, 0, 1 ); 2166 if ( $include ) { 2167 $like_op = 'LIKE'; 2168 $andor_op = 'OR'; 2169 } else { 2170 $like_op = 'NOT LIKE'; 2171 $andor_op = 'AND'; 2172 $term = substr( $term, 1 ); 2173 } 2174 2175 if ( $n && $include ) { 2162 2176 $like = '%' . $wpdb->esc_like( $term ) . '%'; 2163 2177 $q['search_orderby_title'][] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $like ); … … 2165 2179 2166 2180 $like = $n . $wpdb->esc_like( $term ) . $n; 2167 $search .= $wpdb->prepare( "{$searchand}(($wpdb->posts.post_title LIKE %s) OR ($wpdb->posts.post_content LIKE%s))", $like, $like );2181 $search .= $wpdb->prepare( "{$searchand}(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like ); 2168 2182 $searchand = ' AND '; 2169 2183 } … … 2265 2279 if ( $q['search_terms_count'] > 1 ) { 2266 2280 $num_terms = count( $q['search_orderby_title'] ); 2267 $like = '%' . $wpdb->esc_like( $q['s'] ) . '%'; 2281 2282 // If the search terms contain negative queries, don't bother ordering by sentence matches. 2283 $like = ''; 2284 if ( ! preg_match( '/(?:\s|^)\-/', $q['s'] ) ) { 2285 $like = '%' . $wpdb->esc_like( $q['s'] ) . '%'; 2286 } 2268 2287 2269 2288 $search_orderby = '(CASE '; 2289 2270 2290 // sentence match in 'post_title' 2271 $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_title LIKE %s THEN 1 ", $like ); 2291 if ( $like ) { 2292 $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_title LIKE %s THEN 1 ", $like ); 2293 } 2272 2294 2273 2295 // sanity limit, sort as sentence when more than 6 terms … … 2282 2304 2283 2305 // sentence match in 'post_content' 2284 $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 4 ", $like ); 2306 if ( $like ) { 2307 $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 4 ", $like ); 2308 } 2285 2309 $search_orderby .= 'ELSE 5 END)'; 2286 2310 } else {
Note: See TracChangeset
for help on using the changeset viewer.