Custom Fields in Comment form (13 posts)

  1. daxdiri
    Posted 6 years ago #

    I am trying to add a form when a user posts a comment that will allow them to add a rating for the review. A simple 1-5 rating from a dropdown. I've done some googling and the only plugin I was able to find that remotely does this was last udpated in 2006 and doesn't work with WordPress 2.9. I've also tried out "GD Star Rating" but that lets users submit a rating WITHOUT submitting a review, which we dont want.

    I've read about the commentmeta table that WordPress 2.9 introduced, but can't seem to find any documentation on it. Any help on this?

  2. westondeboer
    Posted 6 years ago #

    I haven't looked into it either, but you made me do it right now. Comment meta works just like post_meta. You can add this to your functions.php file:

    // Add action to do after comment is submitted
    // After Comment is submitted
    function comment_ratings($comment_id) {
    	global $wpdb, $user_identity, $user_ID;
    	$rate_userid = $user_ID;
    	$star1 = $_POST['comment_post_ID'];
    	$prevrating = $_POST['prev_rating'];
    	$totalrating = $_POST['total_rating'];
    	$totalrating = ($totalrating + 1);
      $star2 = $_POST['star'];
      // This is where the comment meta is added, just adds number to current comment meta
      update_comment_meta($star1, 'rating', $star2); 
    // If no rating just insert it into the DB
    if ($prevrating == 0){
      update_post_meta($star1, 'rating', $star2);
      update_post_meta($star1, 'total_rating', $totalrating);
    // If it has been rated before Do some math and then insert it
    } else {
     $finalrating = ($prevrating + $star2);
      update_post_meta($star1, 'rating', $finalrating);
      update_post_meta($star1, 'total_rating', $totalrating);

    Two things I have a hidden field of previous rating, so this doesn't have to do an extra mysql call here and I have the star rating form on the comments form.

  3. WayneSmallman
    Posted 6 years ago #

    @poil11, where's the documentation for update_comment_meta() etc?

    I've been hunting high and low and I can't find anything in the Codex.

  4. silentgap
    Posted 6 years ago #

    @WayneSmallman - take a look at these links

    The page is in the codex (http://codex.wordpress.org/Function_Reference/update_comment_meta) but still needs documentation

    *** UPDATE ***
    In the WordPress version number it gives is 2.9, so if your system is older than that, you may need to upgrade - can't speak with any authority on that though

  5. westondeboer
    Posted 6 years ago #

    @WayneSmallman It works just like update_post_meta, so you can just use that as a reference.

  6. tronicscribe
    Posted 6 years ago #

    I'm trying to figure this out as well, but I'm probably not quite as php savvy as you all. I included that function in my file, but I don't see what it does. Do I need to echo something in order for this to work, or add something to my commments.php file? Thanks for the help.

  7. ryanmc
    Posted 6 years ago #

    Use this plugin (http://www.gdstarrating.com/) it is spectacular. I use it on my blog (http://www.justechn.com) and I write reviews all the time. With this plugin I can add my own rating to my reviews, my readers can add theirs, and they can also thumbs up/down comments and the review. Just take a look at one of my review pages (http://www.justechn.com/2009/10/21/review-epson-artisan-810-all-in-one-photo-printer). There are stars on the top right that summarize the ratings, then at the bottom is my detailed rating and in the comment form is a place where readers can rate the review with stars.

  8. mfacer
    Posted 6 years ago #

    @ryanmc - how did you get the "static" stars? Every time I put the stars in to my comments (as per the tutorial for GDStarRating website) it displays a zero rating and seems to allow other users the ability to actually rate that comment. I just want to show what that user rated in the first place!! It's driving me mad.

  9. ryanmc
    Posted 6 years ago #

    The plugin can be hard to grasp at first. I had to do a lot of code searching it get things exactly the way I wanted. I also do not use the built-in integrations. I included the functions directly on my pages so I would have more control over how it worked and looked.

    In my functions.php file I define my own comment function and I use wp_gdsr_comment_integrate_standard_result to display the results in read only. In the comment form I am using wp_gdsr_comment_integrate_standard_rating for the users to vote with.

    Good luck

  10. topinews
    Posted 6 years ago #

    Not sure if this is the right thread to get the solution to my problem but I am posting it here because this thread is related to comments.

    My site runs on Media Temple Shared Grid and GPU usage is something that I always have to worry about. Recently I noticed that the post with a lot od comments on it tends to consume huge amout of GPU compared to posts with no or less comments.

    This post about OMEGLE has about 84 coments and it eats away a lot of GPU on MT. This other post about IRCTC LOGIN has 3 comments and it consumes almost no GPU compared to the previous post. Both above mentioned posts gets equal hits.

    Is there a way to reduce the GPU usage without deleting comments?


  11. aphill70
    Posted 5 years ago #

    I am kinda new here but isn't there a way to use a pager for your comments? that would allow you to have all your comments but your GPU would only have to render the most recent few...

    Just a thought

  12. Regis
    Posted 5 years ago #

    @poil11 and @silentGap: Thanks! Thanks! This is great! I had been looking for hours how to use a custom column in the comments table, but this is MUCH simpler!! I read here and there that custom comment type exist, but I have not seen them anywhere. Anyone know if they exit?

  13. solace10
    Posted 5 years ago #

    Hi folks

    I have a plugin that allows you to add any number of additional extra fields on the comment form. It's not free, but it's not expensive and it's in constant development.

    It doesn't specifically display a rating, but you could easily customise it. Extensive documentation and install instructions are provided.

    Take a look:


Topic Closed

This topic has been closed to new replies.

About this Topic