WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/08/2014 03:11:14 PM (7 years ago)
Author:
kovshenin
Message:

Use the primary meta_query clause when parsing orderby in WP_Query.

When using legacy meta_key, meta_value, etc. arguments in WP_Query,
they're converted into the first clause of a meta_query. By using that
clause instead of the original arguments, we make sure that behavior is
consistent between the two available formats.

props boonebgorges.
fixes #16814.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r29760 r29855  
    22242224        );
    22252225
    2226         $meta_key = $this->get( 'meta_key' );
    2227         if ( ! empty( $meta_key ) ) {
    2228             $allowed_keys[] = $meta_key;
     2226        $primary_meta_key = '';
     2227        $primary_meta_query = false;
     2228        if ( ! empty( $this->meta_query->queries ) ) {
     2229            $primary_meta_query = reset( $this->meta_query->queries );
     2230
     2231            if ( ! empty( $primary_meta_query['key'] ) ) {
     2232                $primary_meta_key = $primary_meta_query['key'];
     2233                $allowed_keys[] = $primary_meta_key;
     2234            }
     2235
    22292236            $allowed_keys[] = 'meta_value';
    22302237            $allowed_keys[] = 'meta_value_num';
     
    22512258                $orderby = 'RAND()';
    22522259                break;
    2253             case $meta_key:
     2260            case $primary_meta_key:
    22542261            case 'meta_value':
    2255                 $type = $this->get( 'meta_type' );
    2256                 if ( ! empty( $type ) ) {
    2257                     $meta_type = $this->meta_query->get_cast_for_type( $type );
    2258                     $orderby = "CAST($wpdb->postmeta.meta_value AS {$meta_type})";
     2262                if ( ! empty( $primary_meta_query['type'] ) ) {
     2263                    $sql_type = $this->meta_query->get_cast_for_type( $primary_meta_query['type'] );
     2264                    $orderby = "CAST($wpdb->postmeta.meta_value AS {$sql_type})";
    22592265                } else {
    22602266                    $orderby = "$wpdb->postmeta.meta_value";
Note: See TracChangeset for help on using the changeset viewer.