Prevent db error when dealing with unexistant parent term. See #12891

git-svn-id: http://svn.automattic.com/wordpress/trunk@15734 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-10-06 12:06:23 +00:00
parent 2a99093ba9
commit 54304cc2d4
2 changed files with 14 additions and 9 deletions

View File

@ -696,8 +696,15 @@ class WP_Object_Query {
foreach ( $this->tax_query as $query ) {
if ( !isset( $query['include_children'] ) )
$query['include_children'] = true;
$query['do_query'] = false;
$sql[] = get_objects_in_term( $query['terms'], $query['taxonomy'], $query );
$sql_single = get_objects_in_term( $query['terms'], $query['taxonomy'], $query );
if ( empty( $sql_single ) )
return ' AND 0 = 1';
$sql[] = $sql_single;
}
if ( 1 == count( $sql ) ) {

View File

@ -466,16 +466,14 @@ function get_objects_in_term( $terms, $taxonomies, $args = array() ) {
return new WP_Error( 'invalid_taxonomy', sprintf( __( 'Invalid Taxonomy: %s' ), $taxonomy ) );
}
$terms = array_unique( (array) $terms );
if ( empty($terms) )
continue;
if ( !in_array( $field, array( 'term_id', 'slug', 'name' ) ) )
$field = 'term_id';
if ( !in_array( $operator, array( 'IN', 'NOT IN' ) ) )
$operator = 'IN';
$terms = array_unique( (array) $terms );
if ( is_taxonomy_hierarchical( $taxonomy ) && $include_children ) {
$children = array();
foreach ( $terms as $term ) {
@ -492,6 +490,9 @@ function get_objects_in_term( $terms, $taxonomies, $args = array() ) {
$field = 'term_id';
}
if ( empty( $terms ) )
return $do_query ? array() : '';
$taxonomies = "'" . implode( "', '", $taxonomies ) . "'";
switch ( $field ) {
@ -527,10 +528,7 @@ function get_objects_in_term( $terms, $taxonomies, $args = array() ) {
break;
}
if ( !$do_query )
return $sql;
return $wpdb->get_col( $sql );
return $do_query ? $wpdb->get_col( $sql ) : $sql;
}
/**