How do I fix Undefined variable using $_POST in function?
Question
I have the following function
but with this error: Notice: Undefined variable: rating
. hoa can I fix it?
function save_comment_meta_rating($comment_id){
if(!empty($_POST['rating']))
$rating = sanitize_text_field($_POST['rating']);
add_comment_meta($comment_id,'rating',$rating);
// Then update the average rating.
update_post_avg_rating( $comment_id );
}
add_action('comment_post','save_comment_meta_rating');
Thanks
0
functions, variables
4 years
2019-11-02T07:56:50-05:00
2019-11-02T07:56:50-05:00 0 Answers
79 views
0
Leave an answer