1

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 ?

1

$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()

0

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 );
  • Please explain your code, rather than just pasting it into the answer box. – s_ha_dum Mar 31 '13 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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