The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Adding a shortcode ...
 
Share:
Notifications
Clear all

Limited Support

Our support team is currently on holiday from December 25, 2025 to January 7, 2026, and replies may be delayed during this period.

We appreciate your patience and understanding while our team is away. Thank you for being part of the wpDiscuz community!

Merry Christmas and Happy Holidays! 🎄

Question [Solved] Adding a shortcode to display the number of likes of a user's comments

3 Posts
2 Users
2 Reactions
1,782 Views
Posts: 18
 leo
Topic starter
(@leo69)
Eminent Member
Joined: 3 years ago

Hello
Good time everyone
I need a code that by placing it in the function of the template, I can display the total number of likes and dislikes of a user by placing a short code.
Thank you for helping me


2 Replies
Asti
Posts: 8204
 Asti
Support
(@asti)
Illustrious Member
Joined: 8 years ago

Hi @mandegar266,

Add this code to the functions.php file: 

add_shortcode('wpdiscuz_likes', 'wpdiscuz_current_user_likes');
function wpdiscuz_current_user_likes(){
    global $wpdb,$user_ID;
    if(!$user_ID){
        return;
    }    $like_count = (int)$wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM `{$wpdb->prefix}wc_users_voted` WHERE `vote_type` = 1 AND `user_id` = %d", $user_ID));
    $dislike_count = (int)$wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM `{$wpdb->prefix}wc_users_voted` WHERE `vote_type` = -1 AND `user_id` = %d", $user_ID));    echo 'Like Count - ' . $like_count .' Dislike Count - ' . $dislike_count;}

 

Then use the following shortcode: 

[wpdiscuz_likes]

Posts: 18
 leo
Topic starter
(@leo69)
Eminent Member
Joined: 3 years ago

I am extremely grateful for your guidance
I have worked with php language to some extent, but I am not familiar with WordPress and Discase functions, and this code of yours was very useful for me.
I wish you the best from Iran


Share: