Support

Account

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 🙂