Ensure that terms with a post count of `0` are not returned in `wp_count_terms()` when `hide_empty => true`. Adds unit test which ensures that `wp_count_terms()` returns `0`.

Props markjaquith.
Fixes #15919.



git-svn-id: https://develop.svn.wordpress.org/trunk@25551 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2013-09-21 16:47:43 +00:00
parent 825faf32da
commit 325b1bf175
2 changed files with 10 additions and 0 deletions

View File

@ -1369,6 +1369,9 @@ function get_terms($taxonomies, $args = '') {
$where .= " AND tt.parent = '$parent'"; $where .= " AND tt.parent = '$parent'";
} }
if ( 'count' == $fields )
$hierarchical = false;
if ( $hide_empty && !$hierarchical ) if ( $hide_empty && !$hierarchical )
$where .= ' AND tt.count > 0'; $where .= ' AND tt.count > 0';

View File

@ -505,4 +505,11 @@ class Tests_Term extends WP_UnitTestCase {
$term2 = get_term_by( 'term_taxonomy_id', $term1['term_taxonomy_id'], 'category' ); $term2 = get_term_by( 'term_taxonomy_id', $term1['term_taxonomy_id'], 'category' );
$this->assertEquals( get_term( $term1['term_id'], 'category' ), $term2 ); $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 );
}
} }