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:
1 2 3 4 5 | $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:
Remove suffix from taxonomies in WordPress
To change content Type of mail in WordPress
WordPress site into maintenance mode Without Plugin
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.
If you have any query or question,tell us in the comment section :). Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.
Comments (1)