[wp-trac] [WordPress Trac] #13176: wp_list_categories pad_counts shows zero for parent term with custom hierarchical taxonomy

WordPress Trac wp-trac at lists.automattic.com
Thu Aug 18 00:52:08 UTC 2011


#13176: wp_list_categories pad_counts shows zero for parent term with custom
hierarchical taxonomy
-------------------------------------------+-----------------------
 Reporter:  michaelh                       |       Owner:  filosofo
     Type:  defect (bug)                   |      Status:  reopened
 Priority:  normal                         |   Milestone:
Component:  Taxonomy                       |     Version:  3.0
 Severity:  normal                         |  Resolution:
 Keywords:  reporter-feedback needs-patch  |
-------------------------------------------+-----------------------

Comment (by valendesigns):

 I'm also using a list of child category ID's in the "include" option. The
 way I'm building the list of categories is to grab all the ID's that have
 0 as there parent and put them into an array with get_categories() and
 then the rest go into the child array. It doesn't show all the parents
 because it thinks they are empty and doesn't pad their counts. Here's the
 code.


 {{{
 if ( ! function_exists( 'premium_get_categories' ) ) {
   function premium_get_categories() {
     $return     = '';
     $parents    = array();
     $children   = array();
     $args = array(
       'orderby' => 'id',
       'order'   => 'ASC'
     );
     $categories = get_categories( $args );

     foreach( $categories as $category )
       if ( $category->category_parent == 0 )
         $parents[] = $category->term_id;
       else
         $children[] = $category->term_id;

     if ( count( $parents ) > 0 )
       $return.= wp_list_categories( 'include=' . implode( ',', $parents )
 . '&title_li=<h4>' . __( 'Topics:' ) .
 '</h4>&show_count=1&pad_counts=1&echo=0' );

     if ( count( $children ) > 0 )
       $return.= wp_list_categories( 'include=' . implode( ',', $children )
 . '&title_li=<h4>' . __( 'Category:' ) .
 '</h4>&show_count=1&pad_counts=1&echo=0' );

     if ( $return !== '' )
       return '<ul id="sidebar-categories">' . $return . '</ul>';
   }
 }
 }}}


 Replying to [comment:6 SergeyBiryukov]:
 > Replying to [comment:4 valendesigns]:
 > > Is that enough information to reproduce the issue?
 >
 > Not exactly. I've just tried to reproduce with this structure:
 > {{{
 > Category 1 (0 posts)
 > — Category 2 (3 posts)
 > — — Category 3 (2 posts)
 > }}}
 >
 > Calling `wp_list_categories('show_count=1&pad_counts=1');` results in:
 > {{{
 > Category 1 (5)
 >     Category 2 (5)
 >         Category 3 (2)
 > }}}
 > Which seems OK.
 >
 > I've also tried to reproduce the original bug report from ticket
 description, and the code seems to work as expected too.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/13176#comment:8>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list