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:

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 1


This answer Count how many posts in category says to use this code

$category = get_category($id);
$count = $category->category_count;
  • Thank you I have used that too but the same result.
    – SanSolo
    Commented Jun 6, 2019 at 2:32
  • If the ID of the category is '640', then the get_category('640') should get you an array of items belonging to that category. Try a print_r of $category (just after the first line in my example) and see the array values returned. Commented Jun 6, 2019 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.