Gravity Forms to ACF Pattern

When you use Gravity Forms to make a post, you can provision ACF fields but what I found was that the data wasn’t showing up correctly until I manually went and updated the created post. I tried using the WordPress wp_update_post() function but found that didn’t do it.

I ended up taking a look at the post_meta in the database directly.1 That’s something that I find myself doing more and more. When you can look directly at evidence, do that. Don’t assume. So what I saw was this . . .
Screenshot of Sequel Pro showing the metadata associated with the post that Gravity Forms created.
You can see that the base custom fields are there. The data is visible.

Now I hit update and refreshed the database view and saw lots of new custom fields get generated. This data associates the human readable fields with the field keys that ACF creates. Note the underscores which prevent those fields from showing up in the backend of WP even if you have view custom fields selected.
New view showing all the new metadata fields that get generated.

I feel like this has something to do with acf/save_post but couldn’t figure out how to make that work. When my knowledge fails,2 I resort to force.

First, I turned on the ability to see the field keys in ACF. It’s easy to miss and easy to forget that this is a Screen Option in WP.
Showing the screen option at the top of the page that allows you to see the ACF field keys.

Once I could see that clearly, I felt typing in all that junk would take a while and be a place where I could make dumb errors. So I cut and pasted the data into a Google Sheet and used my old text manipulation tools to build the function that would build the text I needed.


That was cut/pasted into the plugin and hooked to the after submission hook that Gravity Forms has.

add_action( 'gform_after_submission_1', 'asphs_update_post_content', 10, 2 );

That triggers this function and everything now behaves.

function asphs_update_post_content( $entry, $form ) {
    //getting post
        $post_id = get_post( $entry['post_id'] );
    $i = wp_update_post( $post_id );


1 I use Sequel Pro.

2 And many, many Google searches . . .

Privacy Statement