Skip to content

Instantly share code, notes, and snippets.

@mishterk
Last active January 6, 2022 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mishterk/4e89506f18432caf1866d20f281032a9 to your computer and use it in GitHub Desktop.
Save mishterk/4e89506f18432caf1866d20f281032a9 to your computer and use it in GitHub Desktop.
How to ensure post data from the Gravity Forms Advanced Post Creation Add-on is stored in ACF Custom Database Tables correctly.

Using ACF Custom Database Tables in conjunction with the Gravity Forms Advanced Post Creation Add-on

The Gravity Forms post creation add-on doesn't appear to use ACF's API functions in order to save post meta on newly created posts. It's likely using core meta functions such as update_post_meta() instead of ACF's update_field() and in doing so, the ACF Custom Database Tables plugin doesn't have a chance to intercept the call and store the data in the appropriate custom database table.

In order to make the plugins work together, it's necessary to hook into the post creation process and save the field values using ACF's update_field() function. This will allow ACF Custom Database Tables to locate the appropriate custom DB table and store data there.

An example of this is provided in the below snippets and is based on the Gravity Forms documented approach here.

Caveats

Given the GravityForms Advanced Post Creation Add-on is using core meta functions, ACF Custom Database Tables won't be able to properly bypass core meta storage when configured to do so.

Alternative

For a more cohesive approach, consider using the Advanced Forms Pro plugin for front end forms that create/edit posts. It uses ACF's API functions correctly and is compatible with ACF Custom Database Tables.

<?php
add_action( 'gform_advancedpostcreation_post_after_creation', function ( $post_id, $feed, $entry, $form ){
// Use ACF's update_field() function in order to save the ACF field data correctly. This will
// ensure ACF Custom Database Tables can store the data in the appropriate tables.
update_field( 'my_field_1', $entry['3'], $post_id);
update_field( 'my_field_2', $entry['6'], $post_id);
update_field( 'my_field_3', $entry['8'], $post_id);
}, 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment