Limited Support
Our team is currently on holiday, so support will be limited during this period. Response times may be slower than usual, and some inquiries may be delayed.
We appreciate your patience and understanding, and we’ll resume our usual support by the end of August.
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
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]
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