Make WordPress Core

Changeset 25551


Ignore:
Timestamp:
09/21/2013 04:47:43 PM (11 years ago)
Author:
wonderboymusic
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r25498 r25551  
    13701370    }
    13711371
     1372    if ( 'count' == $fields )
     1373        $hierarchical = false;
     1374
    13721375    if ( $hide_empty && !$hierarchical )
    13731376        $where .= ' AND tt.count > 0';
  • trunk/tests/phpunit/tests/term.php

    r25334 r25551  
    506506        $this->assertEquals( get_term( $term1['term_id'], 'category' ), $term2 );
    507507    }
     508
     509    function test_wp_count_terms() {
     510        $count = wp_count_terms( 'category', array( 'hide_empty' => true ) );
     511        // the terms inserted in setUp aren't attached to any posts, so should return 0
     512        // this previously returned 2
     513        $this->assertEquals( 0, $count );
     514    }
    508515}
Note: See TracChangeset for help on using the changeset viewer.