Post creation $entry['post_id'] is coming back empty [RESOLVED]

Hello,

I am using the Post Creation Add-on to create a post from a user-submitted form. What I would like to do is update the content of the newly created post after the form is submitted. I am using gform_after_submission as follows (taken from gravity docs https://docs.gravityforms.com/gform_after_submission/ ):

add_action( 'gform_after_submission_1', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
 
    //getting post
    $post = get_post( $entry['post_id'] );
	
	//changing post content
       $post->post_content = 'Test content update';

    //updating post
    wp_update_post( $post );
}

Everything in the array seems to be populated as expected except for the post_id here’s the output when I print_r($entry) in the code above:

Array ( 
[id] => 116 
[status] => active 
[form_id] => 1 
[post_id] => 
[date_created] => 2022-02-08 20:49:30
[date_updated] => 2022-02-08 20:49:30

....

)

Without the return of $entry['post_id'] for the post that was created I won’t be able to update the post.

I did come across this post from @Kintivo with a similar question, but this part of the question they asked wasn’t resolved. Hoping someone out there has experienced this and shine some light for me here. Thanks.

If I’m remembering correctly, I think $entry[‘post_id’] is only set when you’re using the older post fields to create posts, not when you’re using the Advanced Post Creation add-on.

Check out the following example in the gform_after_submission doc that shows how to access the created post(s) via the APC add-on from that hook: gform_after_submission - Gravity Forms Documentation

3 Likes

You were spot on. Thanks so much for the reply and your help!

1 Like