Manipulating Comments with Comment Rating
Oct 26th, 2009 by BoB
What is that “comment_karma” in WordPress database?
I had been curious about a field, called “comment_karma” in the WordPress database “comment” table, wondering whether I can use it to store some form of Comment Rating data so that comments can be sorted or skipped based on “comment_karma”. A little Googling got me the answer.
It turned out people were equally curious over two years ago. See http://wordpress.org/support/topic/127000?replies=5 .
The “comment_karma” field is unused. Someone even predicated: “think of it as a plugin waiting to happen.”
Well, the time has come!
Comment Rating is going to use the field to store the Likes-only, Dislikes-only, or combined votes.
Now how do I use the “comment_karma” field?
I was hoping a built-in function allows sorting or exclusion comments. Well, there is a such a function get_comments(). Unfortunately, get_comments() in wp-includes/comment.php hardcodes the ‘orderby’ field to ‘comment_date_gmt’.
Duh! How foolish is that!
So I made a request to the WordPress team. http://wordpress.org/support/topic/324882?replies=1 With my fingers crossed, this problem can be solved in a release in the near future. For now, if you want to take advantage of “comment_karma”, you’ll have to write your own database routine.
What do you think about this plan? Will it be useful? How will you use it?
Please comment.
Awesome idea. I’ve been looking for the same functionality. It’d be great to have the most voted comments at the top of the list.
Well-loved. Like or Dislike:
10
3
[Reply]
hi, i tried to change the following lines:
$defaults = array(’status’ => ”, ‘orderby’ => ‘comment_karma’, ‘order’ => ‘DESC’, ‘number’ => ”, ‘offset’ => ”, ‘post_id’ => 0);
and:
$orderby = ‘comment_karma’; // Hard code for now
but it doesn’t work propably. what else i have to change?
greets, Christian
Like or Dislike:
2
2
[Reply]
BoB
Reply:
November 25th, 2009 at 9:45 am
Christian,
I’d assume that you’re talking about a line in your comments.php. I could be wrong, but I don’t believe that you can do so with standard Wordpress functions. I tried, but to no avail. I found it’s a hardcoded parameter in the Wordpress library. Sent the team an report and haven’t got anything back yet.
If you’re getting impatient for the Wordpress team to fix the problem, you may need to write your own DB access function to get this done.
If you get anywhere, I’d love to see what you come up with.
Like or Dislike:
0
1
[Reply]
Christian
Reply:
November 25th, 2009 at 10:11 am
thank you for you quick reply, is it possible that you post your DB access?
thanks, Christian
Like or Dislike:
1
1
[Reply]