From 6d8a3f3612c0a3993dc2284f95cddc5a786ee307 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 23 Feb 2016 20:14:26 +0000 Subject: [PATCH] Query: Search should match `post_excerpt` in addition to title and content. When ordering search results, exact matches in the post excerpt are weighted above those in post content, but below those in the post title. Props swissspidy, sebastian.pisula. FIxes #35762. Built from https://develop.svn.wordpress.org/trunk@36647 git-svn-id: http://core.svn.wordpress.org/trunk@36614 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 9 +++++---- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index 99df782336..4b3e1e41f7 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -2156,7 +2156,7 @@ class WP_Query { } $like = $n . $wpdb->esc_like( $term ) . $n; - $search .= $wpdb->prepare( "{$searchand}(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like ); + $search .= $wpdb->prepare( "{$searchand}(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_excerpt $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like, $like ); $searchand = ' AND '; } @@ -2280,13 +2280,14 @@ class WP_Query { $search_orderby .= 'WHEN ' . implode( ' OR ', $q['search_orderby_title'] ) . ' THEN 3 '; } - // sentence match in 'post_content' + // Sentence match in 'post_content' and 'post_excerpt'. if ( $like ) { - $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 4 ", $like ); + $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_excerpt LIKE %s THEN 4 ", $like ); + $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 5 ", $like ); } if ( $search_orderby ) { - $search_orderby = '(CASE ' . $search_orderby . 'ELSE 5 END)'; + $search_orderby = '(CASE ' . $search_orderby . 'ELSE 6 END)'; } } else { // single word or sentence search diff --git a/wp-includes/version.php b/wp-includes/version.php index 4b2a3672f2..4492eb35f3 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36646'; +$wp_version = '4.5-alpha-36647'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.