diff --git a/wp-includes/query.php b/wp-includes/query.php index 733eea7dc7..b4aae270b2 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -2300,7 +2300,7 @@ class WP_Query { $like = '%' . $wpdb->esc_like( $q['s'] ) . '%'; } - $search_orderby = '(CASE '; + $search_orderby = ''; // sentence match in 'post_title' if ( $like ) { @@ -2321,7 +2321,10 @@ class WP_Query { if ( $like ) { $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 4 ", $like ); } - $search_orderby .= 'ELSE 5 END)'; + + if ( $search_orderby ) { + $search_orderby = '(CASE ' . $search_orderby . 'ELSE 5 END)'; + } } else { // single word or sentence search $search_orderby = reset( $q['search_orderby_title'] ) . ' DESC';