I have a field group with 3 fields; cars, miles and total_miles. I need to produce a frontend form with only the cars and miles fields viewable (total_miles needs to be hidden.
Once the form is submitted I want to cars * miles and save that value to the hidden total_miles field and save it to the DB.
Something similar to this:
'id' => 'Mixed-Mode',
'post_id' => 'new_post',
'field_groups' => array(698),
'new_post' => array(
'post_type' => 'mixed_mode',
'post_status' => 'publish'),
'submit_value' => 'Submit',
$miles = get_field(‘miles’,698);
$cars = get_field(‘cars’,698);
$Total_miles = get_field(‘total_miles’,698); // This field I want to hide
// I want to take this value and save it to get_field(‘total_miles’,698);
$total = $cars * $miles;
// Once the calculation is complete, display the total
echo $miles.' * '.$cars.' = '.$total_miles;
If you want to calculate the total for each post, then calculating it using PHP code would be more efficient. But, if you want to calculate the total from all posts (e.g. the sum of the totals) and show it in a specific post/page, then saving it to the database would be better.
I hope this helps 🙂
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users