Make WordPress Core


Ignore:
Timestamp:
04/25/2011 05:27:35 PM (13 years ago)
Author:
ryan
Message:

Introduce WP_Meta_Query and relation support. Props scribu, greuben. fixes #17165 #17011

File:
1 edited

Legend:

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

    r17689 r17699  
    848848     */
    849849    var $tax_query;
     850
     851    /**
     852     * Metadata query container
     853     *
     854     * @since 3.2
     855     * @access public
     856     * @var object WP_Meta_Query
     857     */
     858    var $meta_query = false;
    850859
    851860    /**
     
    15261535            unset( $tax_query );
    15271536
    1528             _parse_meta_query( $qv );
    1529 
    15301537            if ( empty($qv['author']) || ($qv['author'] == '0') ) {
    15311538                $this->is_author = false;
     
    19011908        $q = $this->fill_query_vars($q);
    19021909
     1910        // Parse meta query
     1911        $this->meta_query = new WP_Meta_Query();
     1912        $this->meta_query->parse_query_vars( $q );
     1913
    19031914        // Set a flag if a pre_get_posts hook changed the query vars.
    19041915        $hash = md5( serialize( $this->query_vars ) );
     
    22362247        }
    22372248
    2238         if ( !empty( $this->tax_query->queries ) || !empty( $q['meta_key'] ) ) {
     2249        if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) {
    22392250            $groupby = "{$wpdb->posts}.ID";
    22402251        }
     
    24692480        }
    24702481
    2471         // Parse the meta query again if query vars have changed.
    2472         if ( $this->query_vars_changed ) {
    2473             $meta_query_hash = md5( serialize( $q['meta_query'] ) );
    2474             $_meta_query = $q['meta_query'];
    2475             unset( $q['meta_query'] );
    2476             _parse_meta_query( $q );
    2477             if ( md5( serialize( $q['meta_query'] ) ) != $meta_query_hash && is_array( $_meta_query ) )
    2478                 $q['meta_query'] = array_merge( $_meta_query, $q['meta_query'] );
    2479         }
    2480 
    2481         if ( !empty( $q['meta_query'] ) ) {
    2482             $clauses = call_user_func_array( '_get_meta_sql', array( $q['meta_query'], 'post', $wpdb->posts, 'ID', &$this) );
     2482        if ( !empty( $this->meta_query->queries ) ) {
     2483            $clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this );
    24832484            $join .= $clauses['join'];
    24842485            $where .= $clauses['where'];
Note: See TracChangeset for help on using the changeset viewer.