Display the number of comments by author


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function author_comment_count(){
  2.  
  3. $oneText = '1';
  4. $moreText = '%';
  5.  
  6. global $wpdb;
  7.  
  8. $result = $wpdb->get_var('
  9. SELECT
  10. COUNT(comment_ID)
  11. FROM
  12. '.$wpdb->comments.'
  13. WHERE
  14. comment_author_email = "'.get_comment_author_email().'"'
  15. );
  16.  
  17. if($result == 1):
  18.  
  19. echo str_replace('%', $result, $oneText);
  20.  
  21. elseif($result > 1):
  22.  
  23. echo str_replace('%', $result, $moreText);
  24.  
  25. endif;
  26.  
  27. }
  28.  
  29.  
  30.  
  31. To display an author’s total number of comments, use the function like this inside of your comments loop :
  32.  
  33. author_comment_count();
  34.  
  35.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.