From d4eecd8787dea3554c12f8d4f1eda41d5f70efca Mon Sep 17 00:00:00 2001 From: scribu Date: Fri, 24 Sep 2010 14:08:07 +0000 Subject: [PATCH] get_objects_in_term(): include term children when querying by slug. See #12891 git-svn-id: https://develop.svn.wordpress.org/trunk@15654 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/taxonomy.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 73dc7554c4..25d789405f 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -471,19 +471,28 @@ function get_objects_in_term( $terms, $taxonomies, $args = array() ) { if ( !in_array( $operator, array( 'IN', 'NOT IN' ) ) ) $operator = 'IN'; + if ( is_taxonomy_hierarchical( $taxonomy ) && $include_children ) { + $children = array(); + foreach ( $terms as $term ) { + if ( 'term_id' != $field ) { + if ( $term = get_term_by( $field, $term, $taxonomy ) ) + $term = $term->term_id; + else + continue; + } + $children = array_merge( $children, get_term_children( $term, $taxonomy ) ); + $children[] = $term; + } + $terms = $children; + $field = 'term_id'; + } + $taxonomies = "'" . implode( "', '", $taxonomies ) . "'"; switch ( $field ) { case 'term_id': $terms = array_map( 'intval', $terms ); - if ( is_taxonomy_hierarchical( $taxonomy ) && $include_children ) { - $children = $terms; - foreach ( $terms as $term ) - $children = array_merge( $children, get_term_children( $term, $taxonomy ) ); - $terms = $children; - } - $terms = implode( ',', $terms ); $sql = " SELECT object_id