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

git-svn-id: https://develop.svn.wordpress.org/trunk@16843 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
scribu
2010-12-09 17:05:40 +00:00
parent df562b62f4
commit a5cb537970
2 changed files with 33 additions and 18 deletions
+26 -8
View File
@@ -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;