1

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?

3

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

update_post_meta( $parent_post->ID, 'average_wr', $commentdata );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.