Put the following function in your Theme’s functions.php and then put <?php echo tnc_reactions_count($post->ID); ?>
in your single.php to output the numbers. Let me know if it works as I have not tested it completely.
function tnc_reactions_count($post_id){
global $wpdb;
$comments_table = $wpdb->prefix.'comments';
$commentsmeta_table = $wpdb->prefix.'commentmeta';
$get_post_comments = $wpdb->get_results( "SELECT * FROM $comments_table WHERE comment_post_ID='$post_id'", OBJECT );
$funny_total = 0;
$sad_total = 0;
$hate_total = 0;
$good_total = 0;
foreach ($get_post_comments as $key => $value) {
$comment_id = $value->comment_ID;
$query_reaction = $wpdb->get_results( "SELECT * FROM $commentsmeta_table WHERE `comment_id`='$comment_id' AND `meta_key`='comments_reactions'", OBJECT );
foreach ($query_reaction as $key => $value) {
$get_reaction = $value->meta_value;
switch ($get_reaction) {
case 'funny':
$funny_total += 1;
break;
case 'sad':
$sad_total += 1;
break;
case 'hate':
$hate_total += 1;
break;
case 'good':
$good_total += 1;
break;
}
}
}
$output="<h3>Reactions</h3>";
$output .= 'Funny: '.$funny_total;
$output .= 'Sad: '.$sad_total;
$output .= 'Hate: '.$hate_total;
$output .= 'Good: '.$good_total;
return $output;
}
Thanks