Set tax query defaults earlier, for notice prevention and convenience. See #15752
git-svn-id: http://svn.automattic.com/wordpress/trunk@16843 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c22bf34978
commit
e11b831338
|
@ -1491,7 +1491,6 @@ class WP_Query {
|
|||
'taxonomy' => $q['taxonomy'],
|
||||
'terms' => array( $q['term'] ),
|
||||
'field' => 'slug',
|
||||
'operator' => 'IN',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1500,7 +1499,6 @@ class WP_Query {
|
|||
$tax_query_defaults = array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'field' => 'slug',
|
||||
'operator' => 'IN'
|
||||
);
|
||||
|
||||
if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) {
|
||||
|
@ -1550,7 +1548,6 @@ class WP_Query {
|
|||
$tax_query[] = array(
|
||||
'taxonomy' => 'category',
|
||||
'terms' => $q['category__in'],
|
||||
'operator' => 'IN',
|
||||
'field' => 'term_id'
|
||||
);
|
||||
}
|
||||
|
@ -1561,7 +1558,6 @@ class WP_Query {
|
|||
'taxonomy' => 'category',
|
||||
'terms' => $q['category__not_in'],
|
||||
'operator' => 'NOT IN',
|
||||
'field' => 'term_id'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1570,8 +1566,6 @@ class WP_Query {
|
|||
$tax_query[] = array(
|
||||
'taxonomy' => 'post_tag',
|
||||
'terms' => $qv['tag_id'],
|
||||
'operator' => 'IN',
|
||||
'field' => 'term_id'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1579,8 +1573,6 @@ class WP_Query {
|
|||
$tax_query[] = array(
|
||||
'taxonomy' => 'post_tag',
|
||||
'terms' => $q['tag__in'],
|
||||
'operator' => 'IN',
|
||||
'field' => 'term_id'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1589,11 +1581,15 @@ class WP_Query {
|
|||
'taxonomy' => 'post_tag',
|
||||
'terms' => $q['tag__not_in'],
|
||||
'operator' => 'NOT IN',
|
||||
'field' => 'term_id'
|
||||
);
|
||||
}
|
||||
|
||||
_set_tax_query_defaults( $tax_query );
|
||||
|
||||
foreach ( $tax_query as $query ) {
|
||||
if ( ! is_array( $query ) )
|
||||
continue;
|
||||
|
||||
if ( 'IN' == $query['operator'] ) {
|
||||
switch ( $query['taxonomy'] ) {
|
||||
case 'category':
|
||||
|
@ -1945,7 +1941,8 @@ class WP_Query {
|
|||
// Taxonomies
|
||||
if ( !$this->is_singular ) {
|
||||
$this->tax_query = $this->parse_tax_query( $q );
|
||||
if ( !empty( $this->tax_query ) ) {
|
||||
|
||||
if ( ! empty( $this->tax_query ) ) {
|
||||
$clauses = call_user_func_array( 'get_tax_sql', array( $this->tax_query, $wpdb->posts, 'ID', &$this) );
|
||||
|
||||
$join .= $clauses['join'];
|
||||
|
|
|
@ -533,7 +533,9 @@ function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
|
|||
$where = array();
|
||||
$i = 0;
|
||||
|
||||
if ( isset( $tax_query['relation'] ) && strtoupper( $tax_query['relation'] ) == 'OR' ) {
|
||||
_set_tax_query_defaults( $tax_query );
|
||||
|
||||
if ( strtoupper( $tax_query['relation'] ) == 'OR' ) {
|
||||
$relation = 'OR';
|
||||
} else {
|
||||
$relation = 'AND';
|
||||
|
@ -543,13 +545,7 @@ function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
|
|||
if ( ! is_array( $query ) )
|
||||
continue;
|
||||
|
||||
extract( wp_parse_args( $query, array(
|
||||
'taxonomy' => array(),
|
||||
'terms' => array(),
|
||||
'include_children' => true,
|
||||
'field' => 'term_id',
|
||||
'operator' => 'IN',
|
||||
) ) );
|
||||
extract( $query );
|
||||
|
||||
$taxonomies = (array) $taxonomy;
|
||||
|
||||
|
@ -625,6 +621,28 @@ function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
|
|||
return compact( 'join', 'where' );
|
||||
}
|
||||
|
||||
function _set_tax_query_defaults( &$tax_query ) {
|
||||
if ( ! isset( $tax_query['relation'] ) )
|
||||
$tax_query['relation'] = 'AND';
|
||||
|
||||
$defaults = array(
|
||||
'taxonomy' => array(),
|
||||
'terms' => array(),
|
||||
'include_children' => true,
|
||||
'field' => 'term_id',
|
||||
'operator' => 'IN',
|
||||
);
|
||||
|
||||
foreach ( $tax_query as $i => $query ) {
|
||||
if ( ! is_array( $query ) )
|
||||
continue;
|
||||
|
||||
$tax_query[$i] = array_merge( $defaults, $query );
|
||||
|
||||
$tax_query[$i]['terms'] = (array) $tax_query[$i]['terms'];
|
||||
}
|
||||
}
|
||||
|
||||
function _transform_terms( &$terms, $taxonomies, $field, $resulting_field ) {
|
||||
global $wpdb;
|
||||
|
||||
|
|
Loading…
Reference in New Issue