How to get last inserted row ID from WordPress database?

前端 未结 5 756
迷失自我
迷失自我 2020-12-04 10:58

My WordPress plugin has a table with a AUTO_INCREMENT primary key field called ID. When a new row is inserted into the table, I\'d like to get the ID value

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 11:37

    Something like this should do it too :

    $last = $wpdb->get_row("SHOW TABLE STATUS LIKE 'table_name'");
    $lastid = $last->Auto_increment;
    

提交回复
热议问题