Support » How-To and Troubleshooting » [Resolved] Counting how many posts are filed under one tag
8 years, 11 months ago
On the archive page, I want to display how many posts are covered by the relevant category / tag archive.
The following code shows the number of posts of a category:
This category contains <?php $cat = get_the_category(); $cat = $cat; echo $cat->category_count; ?> posts
Now, I want to display the number of posts filed under a tag. I’ve tried it with the following code:
<?php $tag = get_query_var('tag_id'); $tag = $tag; echo $tag->tag_count; ?> posts are filed under this tag.
But (of course) this does not work. Any ideas what I do wrong? Be patient, I’m a php n00b.
Thanks for your help.
Access it through the queried object on the page:
$tag = $wp_query->get_queried_object();