Make WordPress Core

Ticket #27123: 27123.4.patch

File 27123.4.patch, 3.0 KB (added by SergeyBiryukov, 10 years ago)
  • src/wp-includes/taxonomy.php

     
    14771477        if ( $hierarchical && $hide_empty && is_array( $terms ) ) {
    14781478                foreach ( $terms as $k => $term ) {
    14791479                        if ( ! $term->count ) {
    1480                                 $children = _get_term_children( $term->term_id, $terms, reset( $taxonomies ) );
    1481                                 if ( is_array( $children ) )
    1482                                         foreach ( $children as $child )
    1483                                                 if ( $child->count )
     1480                                $children = get_term_children( $term->term_id, reset( $taxonomies ) );
     1481                                if ( is_array( $children ) ) {
     1482                                        foreach ( $children as $child_id ) {
     1483                                                $child = get_term( $child_id, reset( $taxonomies ) );
     1484                                                if ( $child->count ) {
    14841485                                                        continue 2;
     1486                                                }
     1487                                        }
     1488                                }
    14851489
    14861490                                // It really is empty
    14871491                                unset($terms[$k]);
     
    29232927                }
    29242928
    29252929                if ( $term->term_id == $term_id ) {
    2926                         if ( isset( $has_children[$term_id] ) ) {
    2927                                 $current_id = $term_id;
    2928                                 while ( $current_id > 0 ) {
    2929                                         foreach ( $has_children[$current_id] as $t_id ) {
    2930                                                 if ( $use_id ) {
    2931                                                         $term_list[] = $t_id;
    2932                                                 } else {
    2933                                                         $term_list[] = get_term( $t_id, $taxonomy );
    2934                                                 }
    2935                                         }
    2936 
    2937                                         $current_id = isset( $has_children[$t_id] ) ? $t_id : 0;
    2938                                 }
    2939                         }
    29402930                        continue;
    29412931                }
    29422932
  • tests/phpunit/tests/term/getTerms.php

     
    276276                $cranberries = $this->factory->term->create( array( 'name' => 'Cranberries', 'parent' => $fruit, 'taxonomy' => $tax ) );
    277277
    278278                $terms = get_terms( $tax, array( 'parent' => 0, 'cache_domain' => $tax ) );
    279                 $this->assertNotEmpty( $terms );
     279                $this->assertEquals( 2, count( $terms ) );
    280280                $this->assertEquals( wp_list_pluck( $terms, 'name' ), array( 'Cheese', 'Crackers' ) );
    281281        }
    282282
     
    296296                $this->assertEquals( 1, $term->count );
    297297
    298298                $terms = get_terms( $tax, array( 'parent' => 0, 'cache_domain' => $tax ) );
    299                 $this->assertNotEmpty( $terms );
     299                $this->assertEquals( 1, count( $terms ) );
    300300                $this->assertEquals( array( 'Cheese' ), wp_list_pluck( $terms, 'name' ) );
    301301
    302302                _unregister_taxonomy( $tax );
     
    320320                $this->assertEquals( 1, $term->count );
    321321
    322322                $terms = get_terms( $tax, array( 'parent' => 0, 'cache_domain' => $tax ) );
    323                 $this->assertNotEmpty( $terms );
     323                $this->assertEquals( 1, count( $terms ) );
    324324                $this->assertEquals( array( 'term1' ), wp_list_pluck( $terms, 'name' ) );
    325325
    326326                _unregister_taxonomy( $tax );
    327327        }
     328
     329        /**
     330         * @ticket 27123
     331         */
     332        function test_get_terms_child_of() {
     333                $parent = $this->factory->category->create();
     334                $child = $this->factory->category->create( array( 'parent' => $parent ) );
     335
     336                $terms = get_terms( 'category', array( 'child_of' => $parent, 'hide_empty' => false ) );
     337                $this->assertEquals( 1, count( $terms ) );
     338        }
    328339}