When meta_type is passed with orderby => meta_value, orderby must also use CAST() to avoid scenarios like: SELECTing by UNSIGNED and then ordering by CHAR. Adds unit test.
Fixes #21621. Built from https://develop.svn.wordpress.org/trunk@25255 git-svn-id: http://core.svn.wordpress.org/trunk@25223 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -2420,7 +2420,12 @@ class WP_Query {
|
||||
break;
|
||||
case $q['meta_key']:
|
||||
case 'meta_value':
|
||||
$orderby = "$wpdb->postmeta.meta_value";
|
||||
if ( isset( $q['meta_type'] ) ) {
|
||||
$meta_type = get_meta_type( $q['meta_type'] );
|
||||
$orderby = "CAST($wpdb->postmeta.meta_value AS {$meta_type})";
|
||||
} else {
|
||||
$orderby = "$wpdb->postmeta.meta_value";
|
||||
}
|
||||
break;
|
||||
case 'meta_value_num':
|
||||
$orderby = "$wpdb->postmeta.meta_value+0";
|
||||
|
||||
Reference in New Issue
Block a user