We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to sort comments on a selected post by number of votes.
The text was updated successfully, but these errors were encountered:
Old ticket, but +1
Sorry, something went wrong.
I just figured out how to do it: in updownupdown.php we will need these two functions:
function up_down_comment_votes_only_total( $comment_id ) { global $up_down_plugin; if ( !$comment_id ) return 0; $vote_counts = $up_down_plugin->get_comment_votes_total( $comment_id ); return $vote_counts["up"] - $vote_counts["down"] ; } function comment_comparator($a, $b) { $cmp = 0; if ($a->comment_ID != $b->comment_ID) { $votes_a = up_down_comment_votes_only_total( $a->comment_ID ); $votes_b = up_down_comment_votes_only_total( $b->comment_ID ); if ($votes_a != $votes_b) $cmp = $votes_a > $votes_b?-1:1; else $cmp = strtotime($a->comment_date) < strtotime($b->comment_date)?-1:1; } return $cmp; }
And then, on your comments.php, we need:
global $wp_query; $comment_arr = $wp_query->comments; usort($comment_arr, 'comment_comparator'); wp_list_comments('callback=your_callback_name', $comment_arr);
Where your_callback_name is the function you use to render your comments.
your_callback_name
No branches or pull requests
Add an option to sort comments on a selected post by number of votes.
The text was updated successfully, but these errors were encountered: