How to redirect the form submission after post creation

Created by Phil Kurth, Modified on Thu, 3 Nov, 2022 at 8:40 AM by Phil Kurth

When using Advanced Forms Pro to create posts, you may need to redirect to a custom URL and pass the ID of the new post along with the redirect. You may do this by using the af/form/editing/post_created hook and overriding the redirect URL set in the form args on the submission as per the following example.


add_action( 'af/form/editing/post_created', function ( $post, $form, $args ) {
  // If we aren't handling the desired form, return early.
  if ( $form['key'] !== 'FORM_KEY_HERE' ) {
    return;
  }
  
  // Override the redirect URL for this submission using the post ID.
  AF()->submission['args']['redirect'] = 'https://example.com?post=' . $post->ID;
  
}, 10, 3 );


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article