Make WordPress Core

Changeset 16843


Ignore:
Timestamp:
12/09/2010 05:05:40 PM (14 years ago)
Author:
scribu
Message:

Set tax query defaults earlier, for notice prevention and convenience. See #15752

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r16830 r16843  
    14921492                'terms' => array( $q['term'] ),
    14931493                'field' => 'slug',
    1494                 'operator' => 'IN',
    14951494            );
    14961495        }
     
    15011500                    'taxonomy' => $taxonomy,
    15021501                    'field' => 'slug',
    1503                     'operator' => 'IN'
    15041502                );
    15051503
     
    15511549                'taxonomy' => 'category',
    15521550                'terms' => $q['category__in'],
    1553                 'operator' => 'IN',
    15541551                'field' => 'term_id'
    15551552            );
     
    15621559                'terms' => $q['category__not_in'],
    15631560                'operator' => 'NOT IN',
    1564                 'field' => 'term_id'
    15651561            );
    15661562        }
     
    15711567                'taxonomy' => 'post_tag',
    15721568                'terms' => $qv['tag_id'],
    1573                 'operator' => 'IN',
    1574                 'field' => 'term_id'
    15751569            );
    15761570        }
     
    15801574                'taxonomy' => 'post_tag',
    15811575                'terms' => $q['tag__in'],
    1582                 'operator' => 'IN',
    1583                 'field' => 'term_id'
    15841576            );
    15851577        }
     
    15901582                'terms' => $q['tag__not_in'],
    15911583                'operator' => 'NOT IN',
    1592                 'field' => 'term_id'
    15931584            );
    15941585        }
    15951586
     1587        _set_tax_query_defaults( $tax_query );
     1588
    15961589        foreach ( $tax_query as $query ) {
     1590            if ( ! is_array( $query ) )
     1591                continue;
     1592
    15971593            if ( 'IN' == $query['operator'] ) {
    15981594                switch ( $query['taxonomy'] ) {
     
    19461942        if ( !$this->is_singular ) {
    19471943            $this->tax_query = $this->parse_tax_query( $q );
    1948             if ( !empty( $this->tax_query ) ) {
     1944
     1945            if ( ! empty( $this->tax_query ) ) {
    19491946                $clauses = call_user_func_array( 'get_tax_sql', array( $this->tax_query, $wpdb->posts, 'ID', &$this) );
    19501947
  • trunk/wp-includes/taxonomy.php

    r16837 r16843  
    534534    $i = 0;
    535535
    536     if ( isset( $tax_query['relation'] ) && strtoupper( $tax_query['relation'] ) == 'OR' ) {
     536    _set_tax_query_defaults( $tax_query );
     537
     538    if ( strtoupper( $tax_query['relation'] ) == 'OR' ) {
    537539        $relation = 'OR';
    538540    } else {
     
    544546            continue;
    545547
    546         extract( wp_parse_args( $query, array(
    547             'taxonomy' => array(),
    548             'terms' => array(),
    549             'include_children' => true,
    550             'field' => 'term_id',
    551             'operator' => 'IN',
    552         ) ) );
     548        extract( $query );
    553549
    554550        $taxonomies = (array) $taxonomy;
     
    624620
    625621    return compact( 'join', 'where' );
     622}
     623
     624function _set_tax_query_defaults( &$tax_query ) {
     625    if ( ! isset( $tax_query['relation'] ) )
     626        $tax_query['relation'] = 'AND';
     627
     628    $defaults = array(
     629        'taxonomy' => array(),
     630        'terms' => array(),
     631        'include_children' => true,
     632        'field' => 'term_id',
     633        'operator' => 'IN',
     634    );
     635
     636    foreach ( $tax_query as $i => $query ) {
     637        if ( ! is_array( $query ) )
     638            continue;
     639
     640        $tax_query[$i] = array_merge( $defaults, $query );
     641
     642        $tax_query[$i]['terms'] = (array) $tax_query[$i]['terms'];
     643    }
    626644}
    627645
Note: See TracChangeset for help on using the changeset viewer.