我想统计一下用户为其发布的帖子收到的评论总数。例如显示:
所有帖子的总评论数:47有没有办法做到这一点?你能帮帮我吗?
有没有办法做到这一点?你能帮帮我吗?
您可以使用get_comments()
功能如下:
$total = get_comments( array(
\'post_author\' => get_current_user_id(),
\'post_status\' => \'publish\',
\'type\' => \'comment\',
\'count\' => true,
) );
echo \'total comments of your all posts : \' . $total;
只需自定义arguments 根据您的要求/首选项,在上面的示例中,我将检索作者是当前登录用户的已发布帖子的评论总数,但仅针对comment
类型如果您愿意,可以使用status
参数仅限于某些状态,例如。approve
仅统计已批准的评论。
我需要有关如何计算与文本格式相关的单个和多个注释的帮助。Current output:讨论:1条评论和1条答案Desired output:讨论:1条评论和1名回答者,当复数时-如上所述。我一直在反复尝试,我被卡住了。This is my code from my comments.php template:<?php $number_of_parents = comment_counter($post->ID); $number_of_children = $post->