Support

Account

Home Forums General Issues Creating post with Gravity forms, get_fields($post_ID) are kind of empty.

Solving

Creating post with Gravity forms, get_fields($post_ID) are kind of empty.

  • Hello, I am creating posts with a Gravity Forms form and filling a lot of custom fields with it.

    Now what happens is that I generate an email on the add_filter( 'acf/save_post', ...) and this works great, the only thing is that the first time the post is saved (or updated) via the (normal) WordPress update way all the get_fields($post_ID) are empty if I compare them to $_POST['acf'], but visually all the fields are perfectly filled, I can see them in the admin I can also see them perfectly in the acf_form() function, the only thing is that clicking the Update button after the post is created using Gravity Forms all the field via get_fields() are some how empty.

    I was thinking I could some how create a function that saves the post once after it is created to fix this issue, but I was also wondering why this is happening.

    So TL;DR creating posts with the help of Gravity Forms results in somehow empty fields and saving the post once will somehow make add_filter( ‘acf/save_post’, …)think all the fields are changed/updated because they were 'empty before.

  • I think the problem is your variable: $post_ID. Maybe try calling the global $post object and then using $post->ID like so:

    
    <?php // get WP global post object
    global $post;
    
    // you could add a query here to limit your results
    get_fields($post->ID);
    
    // Also if you are grabbing multiple fields you might need to loop through them
    $fields = get_fields($post->ID);
    
    foreach ($fields as $field) {
       // do something with each post
    }
    

    Not sure if that is exactly what you’re looking for.

  • I have the same thing going on – gravity forms created post with form fields mapped directly to existing ACF fields.

    Running wp_post_update() doesn’t get it to kick through either.

  • I’m sure @mvaneijgen moved on long ago but for anyone else wondering about this. Here’s the brute force solution I used to make this work.

    I set a gform action that runs after the form submits.
    add_action( 'gform_after_submission_7', 'asphs_update_post_content', 10, 2 );

    That function maps the custom fields to the acf field keys. (If you look at the database you can see this stuff get generated when you hit update after the failure pattern described in the original post here.).

    So not a great solution but functional. I’d still rather trigger whatever is running on the post update but . . .

    function asphs_update_post_content( $entry, $form ) {
        //getting post
        $post_id = get_post( $entry['post_id'] );
        update_field("_personal_information_first_name","field_5b672aa250437",$post_id);
    	update_field("_personal_information_last_name","field_5b672aa850438",$post_id);
    	update_field("_personal_information_email","field_5b677443f6a3b",$post_id);
    	update_field("_personal_information_phone_number","field_5b672ab050439",$post_id);
    	update_field("_personal_information_university_affiliation","field_5b672ab75043a",$post_id);
    	update_field("_personal_information_private","field_5b672afd156eb",$post_id);
    	update_field("_personal_information_biography","field_5b672adeed779",$post_id);
    	update_field("_personal_information_profile_picture","field_5b672c956690c",$post_id);
    	update_field("_personal_information_expertise","field_5b9871dce76ec",$post_id);
    	update_field("_personal_information","field_5b672a9150436",$post_id);
    	update_field("_location_street_address","field_5b6727dba1a94",$post_id);
    	update_field("_location_city","field_5b6727e5a1a95",$post_id);
    	update_field("_location_state_province","field_5b9daddced8c0",$post_id);
    	update_field("_location_zip_code","field_5b6727eba1a96",$post_id);
    	update_field("_location_country","field_5b6727f5a1a97",$post_id);
    	update_field("_location","field_5b6727c3a1a93",$post_id);
        $i = wp_update_post( $post_id );
    
    }
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.