Greenhoe
Greenhoe

Reputation: 1051

Show Custom Taxonomy Post Count by the Taxonomy ID

I'm looking for a way to show the amount of posts in each Custom Taxonomy by the ID, I would like to show the amount of posts in my sidebar navigation which is not party of any query so I have each of my custom taxonomy IDs but am not sure how to get the post count from them. I see wordpress has the function

 <?php wp_count_terms( $taxonomy, $args ); ?>

Although I need the post count for each of the post count for each individual category from my custom taxonomy not from my entire custom taxonomy.

Upvotes: 0

Views: 7770

Answers (2)

tungpksa
tungpksa

Reputation: 31

You can do this with the current object with get_queried_object():

$posts = get_queried_object();
echo $posts->count;

Upvotes: 0

Greenhoe
Greenhoe

Reputation: 1051

I found the solution incase anyone is looking for it

    <?php 
$args = array(
'post_type' => 'guides',
'post_status' => 'published',
'taxonomy-name' => 'category slug of taxonomy',
'numberposts' => -1,
    );
    echo $num = count( get_posts( $args ) );

?>

Upvotes: 3

Related Questions