Last active
April 4, 2023 14:55
-
-
Save aliciaduffy/6235093 to your computer and use it in GitHub Desktop.
Sort Comments by GD Star Rating Thumbs Up. Store thumbs up count in the comment_karma column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php /* Sort comments by number of thumbs up */ | |
$post_id = get_the_ID(); | |
$comments = get_comments(array( | |
'post_id' => $post_id, | |
"orderby" => "comment_karma", | |
"order" => "DESC" | |
)); | |
?> | |
<?php wp_list_comments('', $comments); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('gdsr_vote_thumb_comment', 'CUSTOM_update_karma', 10, 4); | |
function CUSTOM_update_karma($id, $user, $vote_value) { | |
$this_comment = get_comment($id); | |
$new_comment_karma = $this_comment->comment_karma + $vote_value; | |
$commentarr = array(); | |
$commentarr['comment_ID'] = $id; | |
$commentarr['comment_karma'] = $new_comment_karma; | |
wp_update_comment( $commentarr ); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment