pioneerka
Member
Posted 2 years ago #
Hello,
Is there any way to display number of published posts in a specific category?
This code unfortunately displays number of all published posts, in all categories:
<?php
$published_posts = wp_count_posts()->publish;
?>
Is there a solution?
Thanks in advance .)
You could always do something like this:
$the_test_cat = get_category('5');
$test_count = $the_test_cat->category_count;
pioneerka
Member
Posted 2 years ago #
Or with the template tag, wp_list_categories():
List all categories with post count
wp_list_categories('show_count=1');
List category 5 with post count
wp_list_categories('include=5&show_count=1');
Or use the Category Widget with the Show Count checkbox checked.
pioneerka
Member
Posted 2 years ago #
MichaelH, thank you, but i don't need the title of a category to be displayed, just the number of posts, without any link.