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


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
    // 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'] );
        $i = wp_update_post( $post_id );
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Creating post with Gravity forms, get_fields($post_ID) are kind of empty.’ is closed to new replies.