Support

Account

Home Forums General Issues Issue with Update_Value Reply To: Issue with Update_Value

  • Hi,

    I’ve managed using save_post :

    function my_acf_save_post_6 ($post_id) {
      
        $reviews_of_post = get_posts( array(
            'post_type' => 'ratings',
            'meta_query' => array(
                array(
                    'key' => 'product',
                    'value' => '"' . get_the_ID() . '"',
                    'compare' => 'LIKE',
                ),
            ),
        ) );
      
        foreach ( $reviews_of_post as $review ) {
            $rating_sum += get_field( 'single_rating', 'post_' . $review->ID);
        }
      
      	$value = $rating_sum/count($reviews_of_post);
         
    // do something
    	update_field('field_5de8d2cf1b919', $value, $post_id);	
    }
    
    add_action('acf/save_post', 'my_acf_save_post_6', 20);

    My only issue now, is that I have to go to my Product post and I still have to update in order to see the rating.

    How can I “auto-update” the value without needing to re-publish ?