I'm using PHP everywhere plugin to insert PHP snippets in my page. Specifically, I'm trying to get posts count in a category. Here's my code:
<?php
$count=get_category(607)->count;
echo $count;
?>
But it doesn't display any value, and there is no way of checking what it is returning. The plugin works fine. For example, if I enter echo 1+1
it displays 2.
Please help me. Thanks in advance
I'm using PHP everywhere plugin to insert PHP snippets in my page. Specifically, I'm trying to get posts count in a category. Here's my code:
<?php
$count=get_category(607)->count;
echo $count;
?>
But it doesn't display any value, and there is no way of checking what it is returning. The plugin works fine. For example, if I enter echo 1+1
it displays 2.
Please help me. Thanks in advance
1 Answer
Reset to default 1This answer Count how many posts in category says to use this code
$category = get_category($id);
$count = $category->category_count;