Ticket #21621: meta-type.diff
File meta-type.diff, 2.1 KB (added by , 12 years ago) |
---|
-
wp-includes/query.php
2362 2362 break; 2363 2363 case $q['meta_key']: 2364 2364 case 'meta_value': 2365 $orderby = "$wpdb->postmeta.meta_value"; 2365 if ( isset( $q['meta_type'] ) ) { 2366 $meta_type = get_meta_type( $q['meta_type'] ); 2367 $orderby = "CAST($wpdb->postmeta.meta_value AS {$meta_type})"; 2368 } else { 2369 $orderby = "$wpdb->postmeta.meta_value"; 2370 } 2366 2371 break; 2367 2372 case 'meta_value_num': 2368 2373 $orderby = "$wpdb->postmeta.meta_value+0"; -
wp-includes/meta.php
604 604 } 605 605 606 606 /** 607 * Given a meta type, return the appropriate alias if applicable 608 * 609 * @since 3.5.0 610 * 611 * @see WP_Meta_Query 612 * 613 * @param string $type MySQL type to cast meta_value 614 * @return string MySQL type 615 */ 616 function get_meta_type( $type = '' ) { 617 if ( empty( $type ) ) 618 return 'CHAR'; 619 620 $meta_type = strtoupper( $type ); 621 622 if ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED', 'NUMERIC' ) ) ) 623 return 'CHAR'; 624 625 if ( 'NUMERIC' == $meta_type ) 626 $meta_type = 'SIGNED'; 627 628 return $meta_type; 629 } 630 /** 607 631 * Container class for a multiple metadata query 608 632 * 609 633 * @since 3.2.0 … … 713 737 714 738 foreach ( $this->queries as $k => $q ) { 715 739 $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : ''; 716 $meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';740 $meta_type = get_meta_type( isset( $q['type'] ) ? $q['type'] : '' ); 717 741 718 if ( 'NUMERIC' == $meta_type )719 $meta_type = 'SIGNED';720 elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) )721 $meta_type = 'CHAR';722 723 742 $meta_value = isset( $q['value'] ) ? $q['value'] : null; 724 743 725 744 if ( isset( $q['compare'] ) )