how to check if the post id has a new comment?

this is something goes on my mind

if (hasnewcomment(post->id)){
//echo something

any suggestion or help will do. using get the total comment or anything

please help


  • 1
    I think adding the goal of this might be helpful. Immediately have_comments() comes to mind. Although that may not check for "new" comments. Aug 4, 2016 at 23:03
  • 2
    Can you expand what you need to achieve for us? How do you define "new?" Aug 4, 2016 at 23:04
  • im trying to give notification to the user, if there is a new comment in his post id, echo something, i have tried the have_comment, but this will notify the user once. ive trying to figureout on how to use get_comment_number so that if the get_comment _number is morethan the value , then echo something.
    – user100492
    Aug 4, 2016 at 23:14
  • 2
    @felix So, 'new comment' means a comment they haven't seen yet? Where are you storing the number of comments they have seen?
    – Tim Malone
    Aug 4, 2016 at 23:33
  • @tim i think its in the same page, where does the deafult wordpress comment stored?im using the wordpress default comment, so technically i dont know where does the seen comment stored
    – user100492
    Aug 4, 2016 at 23:41

2 Answers 2


There is a WordPress hook comment_post to retrieve recently added comment and to pass comment id to get_comment you will get the post id.

add_action( 'comment_post', 'show_message_function', 10, 2 );

function show_message_function( $comment_ID, $comment_approved ) {

  $comment_array = get_comment($comment_ID );  

  $comment_post_id = $comment_array->comment_post_ID; 
  • but how can i check if the post id has a new comment?
    – user100492
    Aug 5, 2016 at 11:52

As standard if you turn on manual comment moderation in Settings: Discussion the author of a post will be emailed whenever a comment to their post is made.

Your Answer

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