Update post meta not working on wp_postmeta

I am trying to update post meta values but it does’t work. Only function that is working is get_post_meta and add_post_meta but Update wont work at all. Also I tried to change the values using wpdb->update but that wont work either.

Here is the code.

function rating_system_callback(){

if(  !wp_verify_nonce(  $_POST['nonce'] ,'star_rating_nonce' )){
    wp_die('No nonce found.');
    $total_user_voted = get_post_meta( $_POST['post_id'], 'no_of_user_voted', true );

        add_post_meta($_POST['post_id'], 'no_of_user_voted', 1, true);
    $new_user = $total_user_voted + 1;
    update_post_meta($_POST['post-id'], 'no_of_user_voted', '58');

        add_post_meta($_POST['post_id'], 'total_points_for_post', $_POST['clicked_on'], true);

    $new_points =  $total_votes_for_post + $_POST['clicked_on'];
    update_post_meta($_POST['post-id'], 'total_points_for_post',$new_points);

    $whole_avg = round($new_points / $new_user, 1) ;

    $avg = get_post_meta($_POST['post_id'], 'whole_avg', $whole_avg, true);
        add_post_meta($_POST['post_id'], 'whole_avg', $whole_avg, true);

    update_post_meta($_POST['post-id'], 'whole_avg',$whole_avg);


Read more here: Update post meta not working on wp_postmeta

Leave a Reply

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