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:
parent
825faf32da
commit
325b1bf175
@ -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';
|
||||
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user