Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm looking for Cutom Post Type Category List & Post Count. Here is my code..

            <?php
            $taxonomy = 'project-tags';
            $tax_terms = get_terms($taxonomy);
            ?>

            <?php
            foreach ($tax_terms as $tax_term) {
            echo '<li>' . '<a class="tag" href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '><span class="tag_name">' . $tax_term->name.'</span><span class="tag_count">'. $show_count. '</span></a></li>';
            }?> 

This code works perfect for getting categories under my custom post type. But How do I get number of post count per category ?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

$tax_term->count should contain the number of posts in the category. You may need to add the $args parameter if you want to include subcategory counts.

Docs: get_terms()

share|improve this answer
    
Thanks...It works Perfect ! –  MANnDAaR Jan 16 '12 at 14:23

or simply :

$args = array(
    'show_option_all'    => '',
    'orderby'            => 'name',
    'order'              => 'ASC',
    'style'              => 'list',
    'show_count'         => 1,
    'hide_empty'         => 0,
    'use_desc_for_title' => 1,
    'child_of'           => 0,
    'feed'               => '',
    'feed_type'          => '',
    'feed_image'         => '',
    'exclude'            => '',
    'exclude_tree'       => '',
    'include'            => '',
    'hierarchical'       => 1,
    'title_li'           => __( 'Categories' ),
    'show_option_none'   => __('No categories'),
    'number'             => null,
    'echo'               => 1,
    'depth'              => 0,
    'current_category'   => 0,
    'pad_counts'         => 0,
    'taxonomy'           => 'project-tags',
    'walker'             => null
); 

wp_list_categories( $args );
share|improve this answer
    
Please explain your code, rather than just pasting it into the answer box. –  s_ha_dum Mar 31 '13 at 17:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.