Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the plugin comments rating (thumbs up - thumbs down) on my comments template. It stores "karma" in the db column "comment_karma" in comments table. I am looking for a way to sort wp_list_comments by higher karma to lowest.

Have tried something like

<?php wp_list_comments('callback=mu_custom_callback&orderby=comment_karma&order=DESC') ?>

but it's not working.

thanks

UPDATE

I got it working placing in functions.php `

function comment_comparator($a, $b)
    {
        $compared = 0;
        if($a->comment_karma != $b->comment_karma)
        {
            $compared = $a->comment_karma < $b->comment_karma ? 1:-1;
        }
        return $compared;
        }

and in comments.php

global $wp_query;
    $comment_arr = $wp_query->comments;
    usort($comment_arr, 'comment_comparator');
    wp_list_comments('callback=gtcn_basic_callback', $comment_arr);

Found on this website

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Just incase if you have not checked out the plugin developers page but heres something that you could try

if (function_exists(ckrating_get_comments)) {
$post_id = $post->ID;
$mycomments = ckrating_get_comments(
"post_id=$post_id&status=approve&
orderby=comment_karma&order=DESC");
}
else
$mycomments = null;
wp_list_comments(array(), $mycomments);

UPDATE

I got it working placing in functions.php I got it working placing in functions.php `function comment_comparator($a, $b)

function comment_comparator($a, $b)
    {
        $compared = 0;
        if($a->comment_karma != $b->comment_karma)
        {
            $compared = $a->comment_karma < $b->comment_karma ? 1:-1;
        }
        return $compared;
        }

and in comments.php

global $wp_query;
    $comment_arr = $wp_query->comments;
    usort($comment_arr, 'comment_comparator');
    wp_list_comments('callback=gtcn_basic_callback', $comment_arr);

Found on this website

share|improve this answer
    
Thanks Martin. Of course I have tried that before, result: the voting buttons are disappearing and ordering is not by karma but the default. If I try that without custom callback, comment section is not displayed anymore. Maybe I am putting it in the wrong place (i am pasting it in comments.php replacing the actual wp_list_comments ) –  Andycap May 8 '11 at 11:26
    
sorry I edited your reply instead of my question. –  Andycap May 13 '11 at 16:40
add comment

@ Andycap Thats exactly what i am looking for. but somehow it doesn't work for me. I am pretty shure that i am doing something wrong. Can you explain where exactly to put the code in the functions.php and the comments.php. do i have to add your code or replace it?

share|improve this answer
    
exactly as I wrote, first code goes in functions.php (wherever you want, it's a function), second part goes in comments.php where you call wp_list_comments and call your callback function (of course you have to change callback=gtcn_basic_callback to your callback name). You can find more details on the link I provided in my question. –  Andycap May 19 '11 at 22:14
    
wow, what a fast answer, thanks alot!! i already checked out the link you posted and didn't understand what to do, but with your response i think i know what to do now. so, thanks alot again! –  ilistr May 19 '11 at 22:28
    
just put the code as described and it worked like charm. thanks a alot andycap, you made a chubby pale german as happy as a chubby german can be!! –  ilistr May 19 '11 at 22:57
    
glad to help you! just please upvote my question for some good karma! –  Andycap May 21 '11 at 18:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.