Update Post on Entry Edit

Use this snippet to update the original post created by an entry when that entry is edited. By default, Gravity Forms would create a new post.

This only works with Post fields (and not the Advanced Post Creation add-on).

Code

Filename: gpeb-update-post-on-edit.php

<?php
/**
 * Gravity Perks // Entry Blocks // Update Post on Entry Edit
 * https://gravitywiz.com/documentation/gravity-forms-entry-blocks/
 *
 * Use this snippet to update the original post created by an entry when that entry is edited. By default, Gravity Forms
 * would create a new post.
 *
 * This only works with Post fields (and not the Advanced Post Creation add-on).
 */
add_filter( 'gform_post_data', function( $post_data, $form, $entry ) {
	$post_id = $entry['post_id'];
	if ( $post_id ) {
		$post_data['ID']          = $post_id;
		$post                     = get_post( $post_id );
		$post_data['post_status'] = $post->post_status;
	}
	return $post_data;
}, 10, 3 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.