Skip to content

Instantly share code, notes, and snippets.

@aliciaduffy
Last active April 4, 2023 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aliciaduffy/6235093 to your computer and use it in GitHub Desktop.
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
<?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); ?>
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