WordPress函数:get_comment_count 统计评论数量

追格官方小助手/ 2023年02月18日/ WordPress/ 浏览 1056

WordPress函数 get_comment_count 用来统计整个站点或单篇文章的评论数量。


函数原型:


get_comment_count( int $post_id ): int[]


$post_id, 需要统计评论数量的文章ID。默认为空,则会统计整个站点的评论数量。


返回的结果,类似于下面:


[
	'approved'            => 0,
	'awaiting_moderation' => 0,
	'spam'                => 0,
	'trash'               => 0,
	'post-trashed'        => 0,
	'total_comments'      => 0,
	'all'                 => 0,
]


其实就是统计不同状态评论的数量及总数量。


get_comment_count 只能根据文章ID和评论状态统计评论数量,如果需要更复杂的条件筛选,则可以使用 get_comments 函数,并将其参数 count 设置为true即可。get_comments函数的介绍:《WordPress函数:get_comments 强大的评论查询功能》 和 《WordPress 函数:get_comments 评论查询 参数大全》


发表评论

暂无评论,抢个沙发...

客服 工单