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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.