Gravity Forms can create WordPress posts on submission via the Post Fields module, but Post Fields only map to standard WordPress post fields (title, content, excerpt, custom taxonomies) and not to ACF fields. To populate ACF fields from a Gravity Forms submission, the canonical pattern is the gform_after_submission hook plus update_field calls. Repeater fields need one of three extra patterns because Gravity Forms submits flat data. The dedicated Gravity Forms + ACF add-on plugin is the alternative when you want a UI-driven mapping. Here is each.
Jump to:
- Why Post Fields alone do not cover ACF
- The gform_after_submission hook pattern
- Mapping form fields to ACF fields
- Handling complex ACF field types from a form
- Send Gravity Forms data into an ACF Repeater
- The dedicated Gravity Forms + ACF plugin path
- Validation before save
- User permissions and post status
Why Post Fields alone do not cover ACF
Gravity Forms has a built-in "Post Fields" group that maps form inputs directly to standard WordPress post fields:
- Title
- Body (post_content)
- Excerpt
- Tags
- Category
- Custom Field (writes to
wp_postmetaviaupdate_post_meta)
The Custom Field option does write to wp_postmeta, which is where ACF data lives, BUT it writes only the raw value and not the ACF field-key reference row. The next time ACF reads the field, it may not recognize the value as ACF-managed and may behave unexpectedly (the editor UI shows the value but update_field calls behave oddly).
Using update_field after the form submission is the canonical correct path. The hook is gform_after_submission.
The gform_after_submission hook pattern
gform_after_submission fires after Gravity Forms creates the entry and the post (if Post Fields are configured). The callback receives the entry and the form:
add_action( 'gform_after_submission_5', 'te_populate_acf_from_form', 10, 2 );
// "_5" targets form ID 5; use 'gform_after_submission' to apply to all forms
function te_populate_acf_from_form( $entry, $form ) {
// Get the post ID created by the form (if Post Fields are used)
$post_id = rgar( $entry, 'post_id' );
if ( ! $post_id ) {
// No post was created by Post Fields; nothing to update
return;
}
// Map form field IDs to ACF field names
update_field( 'phone', rgar( $entry, '3' ), $post_id ); // form field ID 3
update_field( 'company', rgar( $entry, '4' ), $post_id );
update_field( 'industry', rgar( $entry, '5' ), $post_id );
update_field( 'is_subscriber', rgar( $entry, '6' ) === 'yes', $post_id );
}rgar() is Gravity Forms' helper for "read get array": it safely reads from the entry array and returns empty string if the key does not exist.
The form field IDs (3, 4, 5, 6 in the example) are visible in the Gravity Forms form editor next to each field. Use these exact IDs in the mapping.
Mapping form fields to ACF fields
For maintainability, define the mapping in a configuration array rather than inline:
add_action( 'gform_after_submission_5', function ( $entry, $form ) {
$post_id = rgar( $entry, 'post_id' );
if ( ! $post_id ) return;
$mapping = [
// form_field_id => acf_field_name
'3' => 'phone',
'4' => 'company',
'5' => 'industry',
'6' => 'is_subscriber',
'7' => 'website_url',
'8' => 'years_in_business',
];
foreach ( $mapping as $form_field_id => $acf_field_name ) {
$value = rgar( $entry, $form_field_id );
update_field( $acf_field_name, $value, $post_id );
}
}, 10, 2 );When the form changes (new field added, existing field renumbered), update the mapping array. The rest of the logic does not need to change.
Handling complex ACF field types from a form
Date fields: Gravity Forms returns the date string in the form's configured format. ACF expects Ymd for storage. Convert:
$date_string = rgar( $entry, '9' ); // e.g., "12/25/2026"
$date_obj = DateTime::createFromFormat( 'm/d/Y', $date_string );
if ( $date_obj ) {
update_field( 'event_date', $date_obj->format( 'Ymd' ), $post_id );
}Checkbox fields: Gravity Forms returns checkbox values as multiple entries with sub-keys (6.1, 6.2, 6.3 for the three checkbox options). Collect them into an array:
$checkboxes = [];
foreach ( [ '6.1', '6.2', '6.3' ] as $sub_key ) {
$val = rgar( $entry, $sub_key );
if ( ! empty( $val ) ) $checkboxes[] = $val;
}
update_field( 'tags', $checkboxes, $post_id );File upload fields: Gravity Forms returns the uploaded file URL. ACF Image fields expect an attachment ID. Convert via attachment_url_to_postid or by sideloading the file:
$file_url = rgar( $entry, '10' );
if ( $file_url ) {
$attachment_id = attachment_url_to_postid( $file_url );
if ( $attachment_id ) {
update_field( 'featured_image', $attachment_id, $post_id );
}
}If the GF upload writes the file outside the media library, you need to sideload it first with media_sideload_image or media_handle_sideload and then use the resulting attachment ID.
Repeater fields: Gravity Forms does not natively support Repeater-shaped submissions. The three ways around that are in the Repeater section below.
Send Gravity Forms data into an ACF Repeater
Gravity Forms is a flat-form builder: each form has a fixed set of fields and each submission produces one entry. There is no built-in "add another row" concept. An ACF Repeater is the opposite, a dynamic array of rows with sub-fields. Three patterns bridge the gap, and I pick by how many rows a submission carries.
Append one Repeater row per submission
Best for "add a testimonial" or "submit your event" forms where each person contributes one item. ACF's add_row() appends without reading the existing array first:
add_action( 'gform_after_submission_7', function ( $entry, $form ) {
$target_post_id = 42; // the post that holds the Repeater, or computed from the form context
$new_row = [
'author_name' => rgar( $entry, '1' ),
'author_email' => rgar( $entry, '2' ),
'testimonial' => rgar( $entry, '3' ),
'rating' => (int) rgar( $entry, '4' ),
'submitted_at' => current_time( 'mysql' ),
'is_approved' => false, // an editor flips this before the row renders
];
add_row( 'testimonials', $new_row, $target_post_id );
}, 10, 2 );The is_approved sub-field is the moderation switch: the front-end template only shows rows where an editor has set it to true.
Fixed row count with grouped sections
For "add up to 3 references" style forms, Section breaks group the fields visually and the hook reads them as N independent rows. Here fields 1 to 12 are four groups of name, email and company:
add_action( 'gform_after_submission_8', function ( $entry, $form ) {
$post_id = rgar( $entry, 'post_id' );
if ( ! $post_id ) return;
$rows = [];
for ( $i = 0; $i < 4; $i++ ) {
$base = ( $i * 3 ) + 1; // form field IDs 1, 4, 7, 10
$name = rgar( $entry, (string) $base );
$email = rgar( $entry, (string) ( $base + 1 ) );
$company = rgar( $entry, (string) ( $base + 2 ) );
if ( ! empty( $name ) ) { // skip rows without a name
$rows[] = [ 'name' => $name, 'email' => $email, 'company' => $company ];
}
}
update_field( 'references', $rows, $post_id );
}, 10, 2 );The limits: the maximum row count is fixed in the form, the editor carries N times the fields, and empty rows are only filtered server-side. It works for three references, not for fifty items.
Dynamic rows through a JSON-encoded hidden field
For genuinely variable row counts, a hidden field (form field ID 5 here) holds a JSON array that front-end JavaScript fills on submit, and the server decodes, validates and sanitizes it. Gravity Forms cannot validate a Repeater shape itself, so the server-side checks are not optional, and they belong in gform_validation, not in gform_after_submission. By the time gform_after_submission runs, Gravity Forms has already validated the form, saved the entry, sent notifications and created the post, so flagging a bad entry there is too late to stop any of that. Rejecting the payload during validation stops the submission before anything is created:
/** Decode and check the JSON rows. Returns the clean rows, or null if the payload is bad. */
function te_clean_item_rows( $raw ) {
$rows = json_decode( (string) $raw, true );
if ( ! is_array( $rows ) || count( $rows ) < 1 || count( $rows ) > 50 ) {
return null; // empty, not an array, or more than 50 rows
}
$clean_rows = [];
foreach ( $rows as $row ) {
$name = is_array( $row ) ? ( $row['item_name'] ?? '' ) : '';
if ( ! is_string( $name ) || '' === $name || mb_strlen( $name ) > 200 ) {
return null;
}
$clean_rows[] = [
'item_name' => sanitize_text_field( $name ),
'quantity' => (int) ( $row['quantity'] ?? 0 ),
'notes' => sanitize_textarea_field( (string) ( $row['notes'] ?? '' ) ),
];
}
return $clean_rows;
}
// Reject a malformed payload before the entry, notifications or post exist.
add_filter( 'gform_validation_9', function ( $validation_result ) {
$form = $validation_result['form'];
if ( null === te_clean_item_rows( rgpost( 'input_5' ) ) ) {
$validation_result['is_valid'] = false;
foreach ( $form['fields'] as &$field ) {
if ( 5 === (int) $field->id ) {
$field->failed_validation = true;
$field->validation_message = 'Add between 1 and 50 items, each with a name.';
break;
}
}
}
$validation_result['form'] = $form;
return $validation_result;
} );
// The payload passed validation; write the sanitized rows.
add_action( 'gform_after_submission_9', function ( $entry, $form ) {
$post_id = rgar( $entry, 'post_id' );
if ( ! $post_id ) return;
$clean_rows = te_clean_item_rows( rgar( $entry, '5' ) );
if ( null === $clean_rows ) return; // defensive; validation already rejected this
update_field( 'items', $clean_rows, $post_id );
}, 10, 2 );The front-end side, added from a theme script, serializes the rows into the hidden input on submit (the "+ add row" UI is your own markup):
document.querySelector('.gform_wrapper').addEventListener('submit', function () {
const rows = Array.from(document.querySelectorAll('.dynamic-row')).map(row => ({
item_name: row.querySelector('[name="item_name"]').value,
quantity: row.querySelector('[name="quantity"]').value,
notes: row.querySelector('[name="notes"]').value,
}));
document.querySelector('input[name="input_5"]').value = JSON.stringify(rows);
});It is the most flexible pattern and the most work (custom JavaScript and styling), so I use it when row counts really vary and the form matters.
Repeater add-ons and other tools
Third-party Gravity Forms add-ons add a UI-driven "Repeater" or "Field Group" field (Gravity Wiz's Gravity Perks suite has one, among others), which removes the custom JavaScript at the cost of another paid dependency. On long-lived client sites I default to the JSON pattern for that reason; where the client manages forms themselves, the add-on can be worth it.
If dynamic-row forms that create Repeater posts keep coming up, Gravity Forms may be the wrong tool. A REST API submission with your own UI (plain, React or Vue) gives full control, WPForms or Fluent Forms may handle dynamic fields better, and a separate post type per "row" with a Relationship back to the parent is often cleaner than a Repeater at all (see nested Flexible Content and editor complexity).
The dedicated Gravity Forms + ACF plugin path
For sites where the form-to-ACF mapping changes frequently and you want a UI-driven approach, the dedicated Gravity Forms + ACF add-on plugins handle the mapping via the Gravity Forms admin. The most-used one is "ACF Frontend Form" (third-party); the official Gravity Forms add-ons handle some ACF field types but coverage varies.
The trade-off:
- Hook-based mapping (above): Code-managed, version-controlled, explicit, supports any ACF field type.
- Plugin-based mapping: UI-managed, easier for non-developers, may not cover every ACF field type.
For agency work I prefer the hook pattern because it lives in code and travels with deploys. For sites where the marketing team needs to add new fields without a developer, the plugin path makes sense.
Validation before save
gform_after_submission fires after Gravity Forms has validated the form and saved the entry. If you need to abort the post update based on a condition the form does not check, do it in the callback:
add_action( 'gform_after_submission_5', function ( $entry, $form ) {
$post_id = rgar( $entry, 'post_id' );
if ( ! $post_id ) return;
// Custom validation: company field must contain a known whitelist
$allowed = [ 'Acme', 'Globex', 'Initech' ];
$company = rgar( $entry, '4' );
if ( ! in_array( $company, $allowed, true ) ) {
// Mark post as pending review instead of populating ACF
wp_update_post( [ 'ID' => $post_id, 'post_status' => 'pending' ] );
return;
}
// Normal mapping
update_field( 'company', $company, $post_id );
}, 10, 2 );For pre-save validation (preventing the form from submitting at all), use gform_validation instead.
User permissions and post status
Gravity Forms creates posts as the currently-logged-in user (or as a configured user if the user is not logged in). For public-facing forms, posts often get created with post_status = 'pending' so an editor can review before publish.
If your ACF population should only run for published posts:
add_action( 'gform_after_submission_5', function ( $entry, $form ) {
$post_id = rgar( $entry, 'post_id' );
if ( ! $post_id || get_post_status( $post_id ) !== 'publish' ) return;
// ACF mapping only for published posts
}, 10, 2 );Or, more commonly, populate ACF regardless of status (so the data is there when the editor reviews and publishes).
For the agency operations side (lead-capture forms, client onboarding forms), see How to Start a WordPress Agency in 2026 Without Burning Yourself Out.
Sources
Authoritative references this article was fact-checked against.
- gform_after_submission (Gravity Forms docs)docs.gravityforms.com
- gform_validation (Gravity Forms docs)docs.gravityforms.com
- Gravity Forms developer hooks (Gravity Forms docs)docs.gravityforms.com
- update_field() function reference (Advanced Custom Fields docs)advancedcustomfields.com





