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:
Scott Taylor
2013-09-05 16:57:08 +00:00
parent 31f26dc3ce
commit 4be84bbdfb
2 changed files with 31 additions and 7 deletions

View File

@@ -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";