Support

Account

Home Forums General Issues Hide one field and save calculated data to it. Reply To: Hide one field and save calculated data to it.

  • Hi @signalwarrant

    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 🙂