Make WordPress Core


Ignore:
Timestamp:
01/11/2011 06:56:59 PM (14 years ago)
Author:
ryan
Message:

Set tag_id for tag queries. Add NOT support to wp_list_filter(). Props scribu. fixes #16170

File:
1 edited

Legend:

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

    r17246 r17251  
    21442144        // Back-compat
    21452145        if ( !empty($this->tax_query->queries) ) {
    2146             $tax_query_in = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'IN' ) );
    2147             if ( !empty( $tax_query_in ) ) {
     2146            $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' );
     2147            if ( !empty( $tax_query_in_and ) ) {
    21482148                if ( !isset( $q['taxonomy'] ) ) {
    2149                     foreach ( $tax_query_in as $a_tax_query ) {
     2149                    foreach ( $tax_query_in_and as $a_tax_query ) {
    21502150                        if ( !in_array( $a_tax_query['taxonomy'], array( 'category', 'post_tag' ) ) ) {
    21512151                            $q['taxonomy'] = $a_tax_query['taxonomy'];
     
    21602160                }
    21612161
    2162                 $cat_query = wp_list_filter( $tax_query_in, array( 'taxonomy' => 'category' ) );
     2162                $cat_query = wp_list_filter( $tax_query_in_and, array( 'taxonomy' => 'category' ) );
    21632163                if ( !empty( $cat_query ) ) {
    21642164                    $cat_query = reset( $cat_query );
    2165                     $cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' );
    2166                     if ( $cat ) {
    2167                         $this->set( 'cat', $cat->term_id );
    2168                         $this->set( 'category_name', $cat->slug );
     2165                    $the_cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' );
     2166                    if ( $the_cat ) {
     2167                        $this->set( 'cat', $the_cat->term_id );
     2168                        $this->set( 'category_name', $the_cat->slug );
    21692169                    }
     2170                    unset( $the_cat );
    21702171                }
     2172                unset( $cat_query );
     2173
     2174                $tag_query = wp_list_filter( $tax_query_in_and, array( 'taxonomy' => 'post_tag' ) );
     2175                if ( !empty( $tag_query ) ) {
     2176                    $tag_query = reset( $tag_query );
     2177                    $the_tag = get_term_by( $tag_query['field'], $tag_query['terms'][0], 'post_tag' );
     2178                    if ( $the_tag ) {
     2179                        $this->set( 'tag_id', $the_tag->term_id );
     2180                    }
     2181                    unset( $the_tag );
     2182                }
     2183                unset( $tag_query );
    21712184            }
    21722185        }
     
    28452858
    28462859        if ( $this->is_category || $this->is_tag || $this->is_tax ) {
    2847             $tax_query_in = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'IN' ) );
    2848 
    2849             $query = reset( $tax_query_in );
     2860            $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' );
     2861
     2862            $query = reset( $tax_query_in_and );
    28502863
    28512864            if ( 'term_id' == $query['field'] )
Note: See TracChangeset for help on using the changeset viewer.