Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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); 
    $parent_post=get_post($commentdata['comment_post_ID']);
    //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

1 Answer 1

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

 
discard

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.