Make WordPress Core

Ticket #21621: 21621.diff

File 21621.diff, 2.3 KB (added by wonderboymusic, 12 years ago)
  • wp-includes/meta.php

    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, $ 
    604604}
    605605
    606606/**
     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 */
     616function 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/**
    607631 * Container class for a multiple metadata query
    608632 *
    609633 * @since 3.2.0
    class WP_Meta_Query { 
    720744                                $key_only_queries[$k] = $q;
    721745                                unset( $this->queries[$k] );
    722746                        }
    723                 }               
    724                
     747                }
     748
    725749                // Split out the meta_key only queries (we can only do this for OR)
    726750                if ( 'OR' == $this->relation ) {
    727751                        foreach ( $this->queries as $k => $q ) {
    class WP_Meta_Query { 
    744768
    745769                foreach ( $queries as $k => $q ) {
    746770                        $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'] : '' );
    753772
    754773                        $meta_value = isset( $q['value'] ) ? $q['value'] : null;
    755774
  • wp-includes/query.php

    diff --git wp-includes/query.php wp-includes/query.php
    index 04286aa..8db0f6e 100644
    class WP_Query { 
    23882388                                                break;
    23892389                                        case $q['meta_key']:
    23902390                                        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                                                }       
    23922397                                                break;
    23932398                                        case 'meta_value_num':
    23942399                                                $orderby = "$wpdb->postmeta.meta_value+0";