2

I need to get author ID by comment ID

Example

functionName($commentID){
   return $authorID; 
}
  • 1
    Have you actually tried something. get_comment()?????? – Pieter Goosen Jul 4 '16 at 11:01
2

Use get_comment to return information about the comment like comment_author_email.

You can then try to get a user by email using get_user_by('email', $comment_author_email).

Once you have the WP_User you should be able to access the ID of that user.

All of this assumes, the comment author's email is used as the user's registration email.

  • get_comment returns user_id You don't need to use the comment_author_email to get the user_id of the comment. If the user wasn't logged in, then it will be 0. – Jeff Nov 24 '17 at 3:39
1

you should use it: <?php get_comment( $id, $output ); ?>

Return

comment_ID 
(integer) The comment ID
comment_post_ID 
(integer) The post ID of the associated post
comment_author 
(string) The comment author's name
comment_author_email 
(string) The comment author's email
comment_author_url 
(string) The comment author's webpage
comment_author_IP 
(string) The comment author's IP
comment_date 
(string) The datetime of the comment (YYYY-MM-DD HH:MM:SS)
comment_date_gmt 
(string) The GMT datetime of the comment (YYYY-MM-DD HH:MM:SS)
comment_content 
(string) The comment's contents
comment_karma 
(integer) The comment's karma
comment_approved 
(string) The comment approbation (0, 1 or 'spam')
comment_agent 
(string) The comment's agent (browser, Operating System, etc.)
comment_type 
(string) The comment's type if meaningfull (pingback|trackback), and empty for normal comments
comment_parent 
(string) The parent comment's ID
user_id 
(integer) The comment author's ID if he is registered (0 otherwise)

Final Code

$comment_id = $commentID; //$commentID your var

$comment = get_comment( $comment_id );

$comment_author_id = $comment -> user_id;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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