Using Custom Fields in Comments

For a private wordpress site I have been using a custom comments table. It just has an added row where people rate the business. Everything is included in the comments table where I don’t need to make a custom table for the ip address, the name, blah blah blah. So now with wordpress 2.9 they have added custom fields for comments so this eliminates the use of me having to do this, YAAAA!

Using custom fields for comments is just like using custom fields for wordpress.

So instead of using: update_post_meta('postid', 'customfield', 'customfieldvalue');

We now use: update_comment_meta('postid', 'customfield', 'customfieldvalue');

So in your plugin or functions.php file you can just do this:

add_action('comment_post','comment_rating');
function comment_rating($comment_id) {
global $wpdb, $user_identity, $user_ID;
$star = $_POST['rating'];
update_comment_meta('postid', 'rating', $star);
}

Again you need to add a rating drop down in your comments.php file (example): <input type=”radio” name=”rating” id=”vote1″ value=”1″ />

About Weston Deboer

I like to use wordpress for any and every website that I work on. No matter how big or how small the website is.
This entry was posted in PHP, Wordpress. Bookmark the permalink.

3 Responses to Using Custom Fields in Comments

  1. ekosulistio says:

    thanks for this tips… very helpfull to me….

  2. Konstantin says:

    Nice! Can’t believe I wasn’t able to figure that out myself. :/

  3. Превосходно!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>