Home › Forums › Front-end Issues › Getting the post_id after creating a post with acf_form() › Reply To: Getting the post_id after creating a post with acf_form()
Hi @polsola
You should be able to do it by using the wp_redirect() function with the acf/save_post hook. But, you need to pass the ID to redirect URL like this:
function my_acf_redirect_after_save( $post_id ) {
// Only do it for "custom_post" post type
if( get_post_type($post_id) != 'custom_post' ){
return;
}
// Only do it on the front end
if( is_admin() ){
return;
}
wp_redirect( 'https://example.com/thank/you/page/?postid=' . $post_id );
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_redirect_after_save', 99);
Then you can get the ID on the thank you page like this:
$post_id = $GET['postid'];
I hope this helps 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.