Make WordPress Core

Changeset 15766


Ignore:
Timestamp:
10/09/2010 10:48:13 AM (16 years ago)
Author:
scribu
Message:

Get rid of redundant $this->meta_query. See #14645

Location:
trunk/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/classes.php

    r15765 r15766  
    545545class WP_Object_Query {
    546546
    547         /**
    548          * List of metadata queries
    549          *
    550          * A query is an associative array:
     547        /*
     548         * Populates the $meta_query property
     549         *
     550         * @access protected
     551         * @since 3.1.0
     552         *
     553         * @param array $qv The query variables
     554         */
     555        function parse_meta_query( &$qv ) {
     556                $meta_query = array();
     557
     558                // Simple query needs to be first for orderby=meta_value to work correctly
     559                foreach ( array( 'key', 'value', 'compare', 'type' ) as $key ) {
     560                        if ( !empty( $qv[ "meta_$key" ] ) )
     561                                $meta_query[0][ $key ] = $qv[ "meta_$key" ];
     562                }
     563
     564                if ( !empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) {
     565                        $meta_query = array_merge( $meta_query, $qv['meta_query'] );
     566                }
     567
     568                $qv['meta_query'] = $meta_query;
     569        }
     570
     571        /*
     572         * Used internally to generate an SQL string for searching across multiple meta key = value pairs
     573         *
     574         * @access protected
     575         * @since 3.1.0
     576         *
     577         * @param array $meta_query List of metadata queries. A single query is an associative array:
    551578         * - 'key' string The meta key
    552579         * - 'value' string|array The meta value
     
    558585         *              Default: 'CHAR'
    559586         *
    560          * @since 3.1.0
    561          * @access public
    562          * @var array
    563          */
    564         var $meta_query = array();
    565 
    566         /*
    567          * Populates the $meta_query property
    568          *
    569          * @access protected
    570          * @since 3.1.0
    571          *
    572          * @param array $qv The query variables
    573          */
    574         function parse_meta_query( $qv ) {
    575                 if ( ! empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) {
    576                         $this->meta_query = $qv['meta_query'];
    577                 }
    578 
    579                 $meta_query = array();
    580                 foreach ( array( 'key', 'value', 'compare', 'type' ) as $key ) {
    581                         if ( ! empty( $qv[ "meta_$key" ] ) )
    582                                 $meta_query[ $key ] = $qv[ "meta_$key" ];
    583                 }
    584 
    585                 if ( ! empty( $meta_query ) ) {
    586                         array_unshift( $this->meta_query, $meta_query );
    587                 }
    588         }
    589 
    590         /*
    591          * Used internally to generate an SQL string for searching across multiple meta key = value pairs
    592          *
    593          * @access protected
    594          * @since 3.1.0
    595          *
    596          * @uses $this->meta_query
    597          *
    598587         * @param string $primary_table
    599588         * @param string $primary_id_column
     
    602591         * @return array( $join_sql, $where_sql )
    603592         */
    604         function get_meta_sql( $primary_table, $primary_id_column, $meta_table, $meta_id_column ) {
     593        function get_meta_sql( $meta_query, $primary_table, $primary_id_column, $meta_table, $meta_id_column ) {
    605594                global $wpdb;
    606595
     
    610599                $where = '';
    611600                $i = 0;
    612                 foreach ( $this->meta_query as $q ) {
     601                foreach ( $meta_query as $q ) {
    613602                        $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
    614603                        $meta_value = isset( $q['value'] ) ? $q['value'] : '';
  • trunk/wp-includes/query.php

    r15765 r15766  
    10821082                unset($this->query);
    10831083                $this->query_vars = array();
    1084                 $this->meta_query = array();
    10851084                unset($this->queried_object);
    10861085                unset($this->queried_object_id);
     
    21152114                }
    21162115
    2117                 list( $meta_join, $meta_where ) = $this->get_meta_sql( $wpdb->posts, 'ID', $wpdb->postmeta, 'post_id' );
     2116                list( $meta_join, $meta_where ) = $this->get_meta_sql( $q['meta_query'], $wpdb->posts, 'ID', $wpdb->postmeta, 'post_id' );
    21182117                $join .= $meta_join;
    21192118                $where .= $meta_where;
  • trunk/wp-includes/user.php

    r15723 r15766  
    459459                        }
    460460
    461                         $this->meta_query[] = $cap_meta_query;
    462                 }
    463 
    464                 list( $meta_join, $meta_where ) = $this->get_meta_sql( $wpdb->users, 'ID', $wpdb->usermeta, 'user_id' );
     461                        $qv['meta_query'][] = $cap_meta_query;
     462                }
     463
     464                list( $meta_join, $meta_where ) = $this->get_meta_sql( $qv['meta_query'], $wpdb->users, 'ID', $wpdb->usermeta, 'user_id' );
    465465                $this->query_from .= $meta_join;
    466466                $this->query_where .= $meta_where;
Note: See TracChangeset for help on using the changeset viewer.