WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on allowing users to rate posts - through the comment meta. Storing and displaying individual ratings is working, however, I would like to be able to store the average rating in the post meta.

I have this thus far, seem to get stuck on passing values to the post meta.

add_action( 'comment_post', 'add_av_rating', 1 );
function add_av_rating($comment_ID)
    $commentdata=get_comment($comment_ID, ARRAY_A); 
    //get rating, get post meta & calc 
update_post_meta($parent_post, 'average_wr', $commentdata);

Even when I put a value such as 'thisText' instead of $commentdata it seems to fail. What am I doing wrong?

share|improve this question
up vote 3 down vote accepted

$parent_post is an object, update_post_meta requires the ID, so should be:

update_post_meta( $parent_post->ID, 'average_wr', $commentdata );
share|improve this answer
Thank you! Instant fix! I still have a lot to learn ;) – maarten May 2 '12 at 17:28

Your Answer


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.