In this quick article, we will see how to get last auto increment id from table in WordPress.
Recently I was working on plugin development and want to get the last auto increment id of table before apply insert query.
I have tried with
LAST_INSERT_ID() function but it was not working so i have checked in mysql official site and get that it’s used for to get auto increment value of most recently executed INSERT statement
Here, I am going to share the solution of this issue. Let’s check the code:
$get_id = $wpdb->get_row("SHOW TABLE STATUS LIKE 'table_name'");
$last_id = $get_id>Auto_increment;
$next_id = $last_id + 1;
Above query will get auto increment value from information_schema. And then just increase it’s value to 1 to generate next id.
You may like other articles:
That’s it.it was so simple to get auto increment id from table. Share your thoughts if you any other simple way to get auto increment value from table.