Support » Plugin: GD Star Rating » [Plugin: GD Star Rating] Comments reordering

  • Hi there,

    firstly, awesome plugin. By far the best ratings plugin for wordpress, and packed with loads of features.

    My wordpress setup is a bit of an odd one, essentially the top level of comments are nominations which users vote on and I’m trying to get them displayed in order of votes as opposed to the traditional wordpress time order. I’ve noticed in forums before that adding this feature has not been possible due to the way that wordpress gets the comments list from the database. I tried hacking this myself and I now see what you mean.

    Then I found this:
    What is described in there is a way to reorder the comments in wordpress based on the currently unused ‘comment karma’ field which is in the database, and I’ve tested this by manually updating the database entry for the comment karma and it works fine. I’m now looking for a way to change the plugin script to allow me to save the overall vote rating (thumb votes) in the karma field which would then allow the comments to be reordered but I’m stuggling a bit with where to put the sql query for this. I was originally just going to write a script that retrieves the up and down votes from the database and then worked out the final vote based on this but doing so would mean the site would be constantly querying the database for every comment and that would just drag.

    I’m hoping to be able to drop something like this in:

    msql_query("INSERT INTO $wpdb->comments (comment_karma) VALUES $vote WHERE comment_id = $id");

    where the ‘votes’ variable is equal to the total of votes up minus votes down. This script should run when a vote is cast, but i’m not sure which function I should be dropping this into. i’m currently looking at the ‘add_vote_comment_thumb’ function in the dp.php file, as that is where the votes are saved to the GD star table of the databse. However, every time I drop that statement into the function and test, I just get a spinning pinwheel when the vote is cast and nothing updates in th karma column of the database.

    Any ideas?


Viewing 6 replies - 1 through 6 (of 6 total)
  • OK, you can ignore all that previous nonsense. That line of code is all wrong, it’s essentially trying to create a row in a table that doesn’t exist. I blame the fact that it’s half one in the morning and i’m coding when my body thinks I should be drinking.

    I think I’ve nailed it now. I used the code from the previous link i posted which sorts the comments according to the comment_karma in the comments.php of my theme and then added this to the end of the add_vote_comment_thumb function (line 174) in db.php in the plugin code>blg folder:

    $up_qry = sprintf("SELECT visitor_recc_plus FROM %sgdsr_data_comment WHERE comment_id = %s", $table_prefix, $id);
    $votes_up = $wpdb->get_var($up_qry);
    $down_qry = sprintf("SELECT visitor_recc_minus FROM %sgdsr_data_comment WHERE comment_id = %s", $table_prefix, $id);
    $votes_down = $wpdb->get_var($down_qry);
    $votes = $votes_up - $votes_down;
    $votes_qry = sprintf("UPDATE %scomments SET comment_karma = $votes WHERE comment_ID = %s", $table_prefix, $id);

    This only updates for visitors, not users, as I don’t have folks logging in to vote on my site. It’s pretty straightforward to put that in though. hope this helps someone, cause it’s been bugging me for days!


    I should also point out for anyone looking to do this that what I’ve done will reorder the comments according to thumb votes, not ratings. I’m sure that the script could be easily adapted for that purpose however.

    Were you able to do it successfully,
    If yes, please do let me know, I have the same problem.


    Hi there,

    Yeah, I got it working using the code above. You do have to go into some of the root files of the plugin to get things working so make sure you back everything up first before trying anything.

    Essentially, the link in my first post give you instructions as to how to use the unused ‘comment karma’ column of the wordpress comments table in the database to order your comments. Then the second piece of code which I wrote shows how to pull the voting (thumbs) data from the plugin table of the database and then drop that into the comments karma column of the comments table. There are other things you can use as opposed to the thumb votes, such as the star ratings. Also, the code above only works for the visitor votes but it’s easy enough to update it for user votes as well (likewise for the star ratings).

    Can you please tell me how I modify this code so that it saves thumbs for visitors and users?



    Thank you so much to help me in reordering the comments according to thumb votes.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: GD Star Rating] Comments reordering’ is closed to new replies.