Update post after form submission

By: Jan Karel Broer | Asked: 04/29/2024
ForumsCategory: Code HelpUpdate post after form submission
Jan Karel BroerJan Karel Broer asked 2 months ago

I'm trying to increment a number value by 1 in ACF field 'rb-huidig_aantal_deelnemers' of the current post after creating a FF entry.

The current post is where the FF form is displayed. I managed to figure out this script, but the value in the field does not change.

The ACF field type is Number.

Can anyone help me out here maybe? Thanks in advance!  

add_action('frm_after_create_entry', 'update_post_after_form_submission', 30, 2);
function update_post_after_form_submission($entry_id, $form_id){
    if ($form_id == 6) { // Aanmelding Training form ID
        $post_id = get_the_ID(); // Gets the ID of the current post
        if (!$post_id) {
            return; // Exit if no post ID found

        $current_value = get_field('rb-huidig_aantal_deelnemers', $post_id);
        $new_value = intval($current_value) + 1;

        // Update custom field called 'rb-huidig_aantal_deelnemers'
        update_field('rb-huidig_aantal_deelnemers', $new_value, $post_id);
1 Answers
Victor Font answered 2 months ago
You shouldn't be using get_the_ID(). This is a WordPress function that works inside the WordPress loop. The frm_after_create_entry action has nothing to do with the WordPress Loop. Your function is exiting in the !$post_d if statement. Assuming Formidable created the post, to retrieve the post_id you should be using $post_id = FrmDb::get_var( 'frm_items', array( 'id' => $entry_id ), 'post_id' );
Jan Karel BroerJan Karel Broer replied 2 months ago

<p>Thanks for helping out and giving more insight, Victor! I already managed to get it working, by storing the post_id in a form field. Get the id goes like this:</p><p>$id = $_POST['item_meta'][117];</p>

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community