WordPress.org

Make WordPress Core


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.