diff --git a/wp-includes/query.php b/wp-includes/query.php index db1deef561..99d43a1a7a 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -670,6 +670,15 @@ class WP_Query { */ var $tax_query = array(); + /** + * Metadata query + * + * @since 3.1.0 + * @access public + * @var array + */ + var $meta_query = array(); + /** * Holds the data for a single object that is queried. * @@ -1363,6 +1372,10 @@ class WP_Query { $this->is_tax = true; } + $meta_query = wp_array_slice_assoc( $qv, array( 'meta_key', 'meta_value', 'meta_compare' ) ); + if ( !empty( $meta_query ) ) + $this->meta_query[] = $meta_query; + if ( empty($qv['author']) || ($qv['author'] == '0') ) { $this->is_author = false; } else { @@ -2166,9 +2179,7 @@ class WP_Query { $where .= ')'; } - // postmeta queries - $meta_query = wp_array_slice_assoc( $q, array( 'meta_key', 'meta_value', 'meta_compare' ) ); - list( $meta_join, $meta_where ) = _wp_meta_sql( array( $meta_query ), $wpdb->posts, 'ID', $wpdb->postmeta, 'post_id' ); + list( $meta_join, $meta_where ) = _wp_meta_sql( $this->meta_query, $wpdb->posts, 'ID', $wpdb->postmeta, 'post_id' ); $join .= $meta_join; $where .= $meta_where;