Ticket #24093: 24093.4.patch
File 24093.4.patch, 2.5 KB (added by , 10 years ago) |
---|
-
meta.php
1036 1036 $meta_compare = '='; 1037 1037 1038 1038 $i = count( $join ); 1039 $alias = $i ? 'mt' . $i : $meta_table;1039 $alias = $i ? 'mt' . $i : 'mt0'; 1040 1040 1041 1041 if ( 'NOT EXISTS' == $meta_compare ) { 1042 1042 $join[$i] = "LEFT JOIN $meta_table"; 1043 $join[$i] .= $i ? " AS $alias" : '';1043 $join[$i] .= " AS $alias"; 1044 1044 $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column AND $alias.meta_key = '$meta_key')"; 1045 1045 1046 1046 $where[$k] = ' ' . $alias . '.' . $meta_id_column . ' IS NULL'; … … 1048 1048 continue; 1049 1049 } 1050 1050 1051 $join[$i] = "INNER JOIN $meta_table"; 1052 $join[$i] .= $i ? " AS $alias" : ''; 1053 $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)"; 1054 1051 if ( !$i ) { 1052 $join[$i] = "INNER JOIN $meta_table"; 1053 $join[$i] .= $i ? " AS $alias" : ' AS mt0'; 1054 $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)"; 1055 } 1056 1055 1057 $where[$k] = ''; 1056 1058 if ( !empty( $meta_key ) ) 1057 1059 $where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key ); … … 1089 1091 if ( ! empty( $where[$k] ) ) 1090 1092 $where[$k] .= ' AND '; 1091 1093 1092 $where[$k] = ' (' . $where[$k] . $wpdb->prepare( "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string})", $meta_value ); 1094 $where[$k] = ' ' . $primary_table . '.' . $primary_id_column . ' IN (' 1095 . ' SELECT ' . $meta_id_column 1096 . ' FROM ' . $meta_table . ' AS ' . $alias 1097 . ' WHERE ' . $where[$k] . $wpdb->prepare( "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value ) 1098 . ')'; 1093 1099 } 1094 1100 1095 1101 $where = array_filter( $where ); -
query.php
2255 2255 $type = $this->get( 'meta_type' ); 2256 2256 if ( ! empty( $type ) ) { 2257 2257 $meta_type = $this->meta_query->get_cast_for_type( $type ); 2258 $orderby = "CAST( $wpdb->postmeta.meta_value AS {$meta_type})";2258 $orderby = "CAST(mt0.meta_value AS {$meta_type})"; 2259 2259 } else { 2260 $orderby = " $wpdb->postmeta.meta_value";2260 $orderby = "mt0.meta_value"; 2261 2261 } 2262 2262 break; 2263 2263 case 'meta_value_num': 2264 $orderby = " $wpdb->postmeta.meta_value+0";2264 $orderby = "mt0.meta_value+0"; 2265 2265 break; 2266 2266 default: 2267 2267 $orderby = "$wpdb->posts.post_" . $orderby;