diff --git wp-includes/meta.php wp-includes/meta.php
index 22b0315..5f5dc73 100644
|
|
function get_meta_sql( $meta_query, $type, $primary_table, $primary_id_column, $ |
604 | 604 | } |
605 | 605 | |
606 | 606 | /** |
| 607 | * Given a meta type, return the appropriate alias if applicable |
| 608 | * |
| 609 | * @since 3.7.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 |
… |
… |
class WP_Meta_Query { |
720 | 744 | $key_only_queries[$k] = $q; |
721 | 745 | unset( $this->queries[$k] ); |
722 | 746 | } |
723 | | } |
724 | | |
| 747 | } |
| 748 | |
725 | 749 | // Split out the meta_key only queries (we can only do this for OR) |
726 | 750 | if ( 'OR' == $this->relation ) { |
727 | 751 | foreach ( $this->queries as $k => $q ) { |
… |
… |
class WP_Meta_Query { |
744 | 768 | |
745 | 769 | foreach ( $queries as $k => $q ) { |
746 | 770 | $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : ''; |
747 | | $meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR'; |
748 | | |
749 | | if ( 'NUMERIC' == $meta_type ) |
750 | | $meta_type = 'SIGNED'; |
751 | | elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) ) |
752 | | $meta_type = 'CHAR'; |
| 771 | $meta_type = get_meta_type( isset( $q['type'] ) ? $q['type'] : '' ); |
753 | 772 | |
754 | 773 | $meta_value = isset( $q['value'] ) ? $q['value'] : null; |
755 | 774 | |
diff --git wp-includes/query.php wp-includes/query.php
index 04286aa..8db0f6e 100644
|
|
class WP_Query { |
2388 | 2388 | break; |
2389 | 2389 | case $q['meta_key']: |
2390 | 2390 | case 'meta_value': |
2391 | | $orderby = "$wpdb->postmeta.meta_value"; |
| 2391 | if ( isset( $q['meta_type'] ) ) { |
| 2392 | $meta_type = get_meta_type( $q['meta_type'] ); |
| 2393 | $orderby = "CAST($wpdb->postmeta.meta_value AS {$meta_type})"; |
| 2394 | } else { |
| 2395 | $orderby = "$wpdb->postmeta.meta_value"; |
| 2396 | } |
2392 | 2397 | break; |
2393 | 2398 | case 'meta_value_num': |
2394 | 2399 | $orderby = "$wpdb->postmeta.meta_value+0"; |