Created
July 8, 2025 12:51
-
-
Save faisalahammad/eb687aaf2b582ab36cb5a97442d69c70 to your computer and use it in GitHub Desktop.
This snippet demonstrates how to automatically redirect users to the newly created post after submitting a Gravity Forms form using the Advanced Post Creation add-on in WordPress. Perfect for guest post submissions, this code ensures users are sent directly to their published post upon form submission.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Gravity Forms: Redirect to Newly Created Post After Submission | |
* | |
* @author Faisal Ahammad <[email protected]> | |
* | |
* Replace 123 with your actual Gravity Form ID. | |
*/ | |
add_filter( 'gform_confirmation_123', 'gfapc_redirect_to_created_post', 10, 4 ); | |
function gfapc_redirect_to_created_post( $confirmation, $form, $entry, $is_ajax ) { | |
// Get the post(s) created by the Advanced Post Creation add-on | |
$created_posts = gform_get_meta( $entry['id'], 'gravityformsadvancedpostcreation_post_id' ); | |
if ( ! empty( $created_posts ) && is_array( $created_posts ) ) { | |
$post_id = $created_posts[0]['post_id'] ?? $created_posts[0]; | |
$redirect_url = get_permalink( $post_id ); | |
if ( $redirect_url ) { | |
$confirmation = array( 'redirect' => $redirect_url ); | |
} | |
} | |
return $confirmation; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment