Home › Forums › General Issues › Hide one field and save calculated data to it. › Reply To: Hide one field and save calculated data to it.
I don’t think saving the total to the database is a good thing to do. It can add loads to your database and make your site slow. Instead, you can create a function to calculate it like this:
function totalMiles( $post_id ){
$miles = get_field('miles', $post_id);
$cars = get_field('cars', $post_id);
return $cars * $miles;
}
Then you can use it like this:
echo totalMiles(698);
If you still want to save it to the database, you need to do it with the acf/save_post hook and the update_field() function.
I hope this makes sense 🙂
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.