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 );
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');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.