I am using this post like system in my WordPress theme and its working fine. My WordPress theme is only for registered user, i mean only registered user can read my post. Now want to display all users list who liked the post in single page under any specific div.

can someone help me with a solution?



According to the code samples in the article _user_liked post meta should hold all the user ids of those who liked it. Something like this should be able to solve it for you

$post_id = get_the_ID();
$users_liked = get_post_meta( $post_id, '_user_liked', true );

if ( '' !== $users_liked && ! empty( $users_liked ) ) {
  <?php foreach ( array_values( $users_liked ) as $user_id ) : 
    $user = get_user_by( 'id', $user_id );
    if ( false === $user ) {
    <li><?php echo $user->user_login; ?></li>
  <?php endforeach; ?>
  • I try this but getting error : Parse error: syntax error, unexpected 'endif' (T_ENDIF) – gul rathod Aug 30 '17 at 17:05
  • @gulrathod Yes, my bad. Try the updated code – Z. Zlatev Aug 30 '17 at 18:58
  • thank you :) its working, i am getting user name list who like a current post. i am getting only user name, can you please tell me if i want user name with profile link or you can say author link, how can i get ??? – gul rathod Sep 1 '17 at 5:20

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