diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 9ae219f688..8e1898e29f 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -1369,6 +1369,9 @@ function get_terms($taxonomies, $args = '') { $where .= " AND tt.parent = '$parent'"; } + if ( 'count' == $fields ) + $hierarchical = false; + if ( $hide_empty && !$hierarchical ) $where .= ' AND tt.count > 0'; diff --git a/tests/phpunit/tests/term.php b/tests/phpunit/tests/term.php index 6b35f4e2f8..40567b5cef 100644 --- a/tests/phpunit/tests/term.php +++ b/tests/phpunit/tests/term.php @@ -505,4 +505,11 @@ class Tests_Term extends WP_UnitTestCase { $term2 = get_term_by( 'term_taxonomy_id', $term1['term_taxonomy_id'], 'category' ); $this->assertEquals( get_term( $term1['term_id'], 'category' ), $term2 ); } + + function test_wp_count_terms() { + $count = wp_count_terms( 'category', array( 'hide_empty' => true ) ); + // the terms inserted in setUp aren't attached to any posts, so should return 0 + // this previously returned 2 + $this->assertEquals( 0, $count ); + } }