WordPress comments – bbird.me http://bbird.me WordPress quick tips Wed, 08 Aug 2018 16:39:07 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.8 How to get commenter ID in WordPress http://bbird.me/get-commenter-id-wordpress/ http://bbird.me/get-commenter-id-wordpress/#respond Mon, 06 Jun 2016 10:08:29 +0000 http://bbird.me/?p=522 If you want to output some data (such as biographical info or personal website) for the person who commented on

Post How to get commenter ID in WordPress je prvi puta viđen na bbird.me.

]]>
If you want to output some data (such as biographical info or personal website) for the person who commented on WordPress post or page, you should be able to get the user ID so you could use it for the_author_meta() function. One of the ways to do it is by using the following code – the first line returns commenter ID, while other lines returns some specific data:

<?php 
$user_id=$comment->user_id;
?>

<p class="commenter-bio"><?php the_author_meta('description',$user_id); ?></p>
<p class="commenter-url"><a href="<?php the_author_meta('user_url',$user_id); ?>" target="_blank"><?php the_author_meta('user_url',$user_id); ?></a></p>

But at this point, if you’re asking yourself  “What is the ID for anonymous commenter”, your question is right on the spot. I believe that this code can be useful only if you allow only registered users to comment on your posts, which was exactly the case I had which that led me to research this method.

Also, even if you allow anyone to post comments on your blog, the $user_id should return 0 for anonymous commenters (whoever is not registered as user, those are).

Post How to get commenter ID in WordPress je prvi puta viđen na bbird.me.

]]>
http://bbird.me/get-commenter-id-wordpress/feed/ 0