michaellevelup

Show comment count

Oct 26th, 2022
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. function post_comment_count() {
  2.  
  3.     function comment_count( $count ) {
  4.         if ( ! is_admin() ) {
  5.             global $post;
  6.             $comments_by_type = &separate_comments(get_comments('status=approve&post_id='. $post->ID ));
  7.             return count($comments_by_type['comment']);
  8.         }
  9.         else {
  10.             return $count;
  11.         }
  12.     }
  13.  
  14.     add_filter('get_comments_number', 'comment_count', 0);
  15.      
  16.     $actual_comment_count = get_comments_number();
  17.      
  18.     return $actual_comment_count;
  19. }
  20.  
  21. add_shortcode('post_comment_count', 'post_comment_count');
Advertisement
Add Comment
Please, Sign In to add comment