• Hi, please I want to know how can I show the total of posts for the current custom taxonomy. With categories I foudned a code, but with custom taxonomies I didn’t!

    I’m using the code below to show the name of the actual taxonomy slug:
    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?>

    And I need something to show the total number of posts to it.

    Thanks for all!

Viewing 1 replies (of 1 total)
  • Hey wasferraz,

    You can get so :

    $taxonomy = "portfolio_type"; // register_taxonomy("portfolio_type", ....
    $post_type = "portfolio"; // register_post_type("portfolio", ....
    $tag_id = 5; // category id (tag_id)
    
    $term = get_term($tag_id, $taxonomy );
    $args = array( 'post_type' => $post_type, $taxonomy => $term->name );
    
    echo "Total Posts (".count($myposts = get_posts( $args )).")";
Viewing 1 replies (of 1 total)
  • The topic ‘How to show total posts of current custom taxonomy?’ is closed to new replies.