I have a voting function for comments which needs to display the avatars of the users who voted for a specific comment. I am having trouble getting the user id of the voter ($supporter). All I seem to get is the user ID of the user who made the comment > I need to get the user ID of the user who voted.
My function:
function addServiceSupporter($comment_id, $user_id) {
add_comment_meta( $comment_id, 'supporting_user', $user_id, false );
}
So the $user_id is stored under meta_value in the wp_commentmeta table.
Before this function I have this the following which seems to have a user_id in it.
/**
* After an ajax call try to add the supporter
*/
if (isset($_POST['new_service'])) {
$new_service_supporter = $_POST['new_service'];
try {
addServiceSupporter($new_service_supporter['comment_id'], $new_service_supporter['user_id']);
} catch (Exception $e) {
print_r($e);
}
die;
}
The call:
foreach($supporters as $supporter) {
$supporting_user = get_comment_meta(get_comment_ID(),'supporting_user', true);
$avatar = get_avatar($supporting_user, 24 );
echo $avatar;
}
I also have tried:
$avatar = get_avatar($supporting_user, 24 );
But that of course gives the avatar of the user currently active on the page.
How do I get the $user_id aka meta_value of this comment_meta?
The result should be: Comment votes (or likes if you want) by users to the comments of others. Then showing the avatars of the people who voted. My problem = how to get the user id of the voters (not the comment author, not the current user) so I can show the right avatar?
foreach($supporters as $supporter) {
?