I have a plugin to add a 'like' to a comment, each 'like' is stored in a table called likes_comments
, I'm trying to sort the output of wp_list_comments
according to how many likes each comment has, I'd like the comment with the most likes to appear at the top.
Here's what I'm using to call wp_list_comments
:
<?php global $wp_query;
$comment_arr = $wp_query->comments; usort($comment_arr, 'comment_comparator');
wp_list_comments('callback=my_callback', $comment_arr);
?>
And here's my function:
function comment_comparator($a, $b)
{
$compared = 0;
if($a->likes_comments != $b->likes_comments)
{
$compared = $a->likes_comments < $b->likes_comments ? 1:-1;
}
return $compared;
}
if($a->likes_comments == 0)
{
$compared = $compared2;
}
I'm completely stuck with this, any help at all would be greatly appreciated.