Increment acf fields by submitted input values (via acf form)
-
Hello,
I have 2 acf fields on a page displaying a number (km and time counter).
I want the visitor to be able to add their own km and time numbers with an acf form.I created the form and displayed it on my page, then when I submit the form with values, both of acf fields are updated, but I want them to be increment (sum between current acf field number + submitted ones).
I used a post action with “update post action” settings because I want to increment number before to save them and the following code:
add_filter('acfe/form/submit/post_args/form=km-time-form', 'my_form_post_args', 10, 4); function my_form_post_args($args, $type, $form, $action){ /* * Get the form input value named 'my_field' * This is the value entered by the user during the form submission */ $input_km_field = get_field('km_amount'); $input_time_field = get_field('time_amount'); // here I want to get the current value of those fields... $current_km_field = get_field('km_amount', $args); $current_time_field = get_field('time_amount', $args); // ...to increment here if($input_km_field < 0 && !empty($input_km_field)) { $args['field_603d2b9808650'] += $input_km_field; } if($input_time_field < 0 && !empty($input_time_field)) { $args['field_603d2bcd870a4'] += $input_time_field; } // return return $args; }
I used $args as the post ID allowing me to get the DB value of the field (can’t remember where I saw that) but it’s not working.
What am I doing wrong ? Is there a way to do that ?Thank you !
- The topic ‘Increment acf fields by submitted input values (via acf form)’ is closed to new replies.