mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Avoid invalid SQL when building ORDER BY clause using long search strings.
The introduction of negative search terms in 4.4 [34934] introduced the possibility that the ORDER BY clause of a search query could be assembled in such a way as to create invalid syntax. The current changeset fixes this by ensuring that the ORDER BY clause corresponding to the search terms is excluded when it would otherwise be empty. Props salvoaranzulla. Fixes #35361. git-svn-id: https://develop.svn.wordpress.org/trunk@36251 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2268,7 +2268,7 @@ class WP_Query {
|
||||
$like = '%' . $wpdb->esc_like( $q['s'] ) . '%';
|
||||
}
|
||||
|
||||
$search_orderby = '(CASE ';
|
||||
$search_orderby = '';
|
||||
|
||||
// sentence match in 'post_title'
|
||||
if ( $like ) {
|
||||
@@ -2289,7 +2289,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';
|
||||
|
||||
Reference in New Issue
Block a user