Ticket #24093: 24093.3.patch
File 24093.3.patch, 2.9 KB (added by , 10 years ago) |
---|
-
meta.php
944 944 945 945 $key_only_queries = array(); 946 946 $queries = array(); 947 947 948 948 // Split out the queries with empty arrays as value 949 949 foreach ( $this->queries as $k => $q ) { 950 950 if ( isset( $q['value'] ) && is_array( $q['value'] ) && empty( $q['value'] ) ) { … … 998 998 $meta_compare = '='; 999 999 1000 1000 $i = count( $join ); 1001 $alias = $i ? 'mt' . $i : $meta_table;1001 $alias = $i ? 'mt' . $i : 'mt0'; 1002 1002 1003 1003 if ( 'NOT EXISTS' == $meta_compare ) { 1004 1004 $join[$i] = "LEFT JOIN $meta_table"; 1005 $join[$i] .= $i ? " AS $alias" : '';1005 $join[$i] .= " AS $alias"; 1006 1006 $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column AND $alias.meta_key = '$meta_key')"; 1007 1007 1008 1008 $where[$k] = ' ' . $alias . '.' . $meta_id_column . ' IS NULL'; … … 1010 1010 continue; 1011 1011 } 1012 1012 1013 $join[$i] = "INNER JOIN $meta_table"; 1014 $join[$i] .= $i ? " AS $alias" : ''; 1015 $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)"; 1016 1013 if ( !$i ) { 1014 $join[$i] = "INNER JOIN $meta_table"; 1015 $join[$i] .= $i ? " AS $alias" : ' AS mt0'; 1016 $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)"; 1017 } 1018 1017 1019 $where[$k] = ''; 1018 1020 if ( !empty( $meta_key ) ) 1019 1021 $where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key ); … … 1051 1053 if ( ! empty( $where[$k] ) ) 1052 1054 $where[$k] .= ' AND '; 1053 1055 1054 $where[$k] = ' (' . $where[$k] . $wpdb->prepare( "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string})", $meta_value ); 1056 // $where[$k] = ' (' . $where[$k] . $wpdb->prepare( "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string})", $meta_value ); 1057 1058 $where[$k] = ' ' . $primary_table . '.' . $primary_id_column . ' IN (' 1059 . ' SELECT ' . $meta_id_column 1060 . ' FROM ' . $meta_table . ' AS ' . $alias 1061 . ' WHERE ' . $where[$k] . $wpdb->prepare( "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value ) 1062 . ')'; 1055 1063 } 1056 1064 1057 1065 $where = array_filter( $where ); -
query.php
2654 2654 case 'meta_value': 2655 2655 if ( isset( $q['meta_type'] ) ) { 2656 2656 $meta_type = $this->meta_query->get_cast_for_type( $q['meta_type'] ); 2657 $orderby = "CAST( $wpdb->postmeta.meta_value AS {$meta_type})";2657 $orderby = "CAST(mt0.meta_value AS {$meta_type})"; 2658 2658 } else { 2659 $orderby = " $wpdb->postmeta.meta_value";2659 $orderby = "mt0.meta_value"; 2660 2660 } 2661 2661 break; 2662 2662 case 'meta_value_num': 2663 $orderby = " $wpdb->postmeta.meta_value+0";2663 $orderby = "mt0.meta_value+0"; 2664 2664 break; 2665 2665 case 'comment_count': 2666 2666 $orderby = "$wpdb->posts.comment_count";