Support

Account

Home Forums ACF PRO How to create a calculated ACF field (saved in the DB) Reply To: How to create a calculated ACF field (saved in the DB)

  • what about using this: wp_update_post( $my_post );

    • inside update_value filter?
    • inside save_post action?

    i use them to update post_title or post_content with values that come from get_field

    or the save action: (all you need is a hidden field with name “totalprice“)

    function my_acf_update_totalprice($post_id)
    {
        $total = get_field('price') * get_field('qty');
        $value = $total;
        $field_name = "totalprice";
        update_field($field_name, $value, $post_id);
    }
    add_action('save_post', 'my_acf_update_totalprice');