Changeset 27125
- Timestamp:
- 02/07/2014 07:53:01 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r27115 r27125 3005 3005 if ( $term->term_id == $term_id ) { 3006 3006 if ( isset( $has_children[$term_id] ) ) { 3007 foreach ( $has_children[$term_id] as $t_id ) { 3008 if ( $use_id ) { 3009 $term_list[] = $t_id; 3010 } else { 3011 $term_list[] = get_term( $t_id, $taxonomy ); 3007 $current_id = $term_id; 3008 while ( $current_id > 0 ) { 3009 foreach ( $has_children[$current_id] as $t_id ) { 3010 if ( $use_id ) { 3011 $term_list[] = $t_id; 3012 } else { 3013 $term_list[] = get_term( $t_id, $taxonomy ); 3014 } 3012 3015 } 3016 3017 $current_id = isset( $has_children[$t_id] ) ? $t_id : 0; 3013 3018 } 3014 3019 } -
trunk/tests/phpunit/tests/term/getTerms.php
r27108 r27125 274 274 $this->assertEquals( wp_list_pluck( $terms, 'name' ), array( 'Cheese', 'Crackers' ) ); 275 275 } 276 277 function test_get_terms_grandparent_zero() { 278 $tax = 'food'; 279 register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); 280 281 $cheese = $this->factory->term->create( array( 'name' => 'Cheese', 'taxonomy' => $tax ) ); 282 $cheddar = $this->factory->term->create( array( 'name' => 'Cheddar', 'parent' => $cheese, 'taxonomy' => $tax ) ); 283 $spread = $this->factory->term->create( array( 'name' => 'Spread', 'parent' => $cheddar, 'taxonomy' => $tax ) ); 284 $post_id = $this->factory->post->create(); 285 wp_set_post_terms( $post_id, $spread, $tax ); 286 $term = get_term( $spread, $tax ); 287 $this->assertEquals( 1, $term->count ); 288 289 $terms = get_terms( $tax, array( 'parent' => 0, 'cache_domain' => $tax ) ); 290 $this->assertNotEmpty( $terms ); 291 $this->assertEquals( array( 'Cheese' ), wp_list_pluck( $terms, 'name' ) ); 292 293 _unregister_taxonomy( $tax ); 294 } 295 296 function test_get_terms_seven_levels_deep() { 297 $tax = 'deep'; 298 register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); 299 $parent = 0; 300 $t = array(); 301 foreach ( range( 1, 7 ) as $depth ) { 302 $t[$depth] = $this->factory->term->create( array( 'name' => 'term' . $depth, 'taxonomy' => $tax, 'parent' => $parent ) ); 303 $parent = $t[$depth]; 304 } 305 $post_id = $this->factory->post->create(); 306 wp_set_post_terms( $post_id, $t[7], $tax ); 307 $term = get_term( $t[7], $tax ); 308 $this->assertEquals( 1, $term->count ); 309 310 $terms = get_terms( $tax, array( 'parent' => 0, 'cache_domain' => $tax ) ); 311 $this->assertNotEmpty( $terms ); 312 $this->assertEquals( array( 'term1' ), wp_list_pluck( $terms, 'name' ) ); 313 314 _unregister_taxonomy( $tax ); 315 } 276 316 }
Note: See TracChangeset
for help on using the changeset viewer.