WP Database Operations
Last Updated: March 10, 2022
You may need to follow database-related code when you develop plugins for WordPress
How to get the last inserted id of the table?
You can use the following code straight after the $wpdb->insert()
$lastid = $wpdb->insert_id;
Make sure you have the primary key, auto-increment, unique for the id column