I want to count the total number of comments the user has received for his published posts. for example show:

total comments of your all posts : 47

Is there a way to do this? Can you help me?

1 Answer 1


You can use the get_comments() function like so:

$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;

Just customize the arguments based on your requirements/preferences, and in the above example, I'm retrieving the total number of comments for published posts where the author is the currently logged-in user, but only for comments of the comment type.

And if you want, you can use the status argument to limit to certain status only, e.g. approve to count approved comments only.

  • 1
    I used this code but got an error A major error has occurred on this website. Jan 27, 2022 at 12:56
  • Sorry about that, I forgot a , after the 'publish'. So please try again?
    – Sally CJ
    Jan 27, 2022 at 13:16
  • I meant, I have revised the code (but I simply added the missing comma/,). So let me know how it goes, even if it doesn't work for you.
    – Sally CJ
    Jan 27, 2022 at 13:47
  • 1
    Thanks a lot . This code works properly now. Jan 28, 2022 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.