最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Why get_category() function is not working not working when embedded in a page?

programmeradmin2浏览0评论

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

Share Improve this question asked Jun 6, 2019 at 1:55 SanSoloSanSolo 1035 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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

$category = get_category($id);
$count = $category->category_count;
发布评论

评论列表(0)

  1. 暂无评论