douhulao7642 2017-06-07 14:10
浏览 69
已采纳

如何在wordpress中获得个人评论的回复计数

I use traded comments so each comments receive multiple replies in it. I need to get replies count of each individual comment. I don't need the total replies count of all the comments.

I tried to use this code:

$comment_id = get_comment_ID();

$childrenCount = get_comment_meta( $comment_id, "childrenCount" );

$childrenCountNumber = count($childrenCount);

echo $childrenCountNumber

The other way round that shows total replies which not what I'm looking for.. This code shows all the replies of all the comments.`

Code in functions.php

function replies_counter($id){
global $wpdb;
$query = "SELECT COUNT(comment_post_id) AS count FROM $wpdb->comments 
WHERE `comment_approved` = 1 AND `comment_post_ID` = $id AND 
`comment_parent` = 0";
$parents = $wpdb->get_row($query);
return $parents->count;
}

Then echo out in the template page:

$parents_count = replies_counter($post->ID);
$children_count = $post->comment_count - $parents_count;

echo $children_count;

This one is all about getting total replies count of all the comments. But I need replies count of each comment individually.

It will be nice if someone help me.

  • 写回答

2条回答 默认 最新

  • douquan3294 2017-06-07 14:49
    关注

    why don't you write such a custom function to get subcomments for each individual comment by ID like this?

    function subreplies_counter($id){
      global $wpdb;
      $query = "SELECT COUNT(comment_ID) AS count FROM $wpdb->comments 
      WHERE `comment_approved` = 1 AND `comment_parent` = $id";
      $data = $wpdb->get_row($query);
      return $data->count;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料