WordPress' post_id is not continuous, so I want to use a custom post_id in wordpress when post an article.
For example, I want to post an article as |id=2in database wp_posts, I got the position ofid=1` , what do I need to do in my function? I add it to my theme's functions.php
function reuse_old_id(){
global $wpdb;
$lastID = $wpdb->get_var("SELECT ID FROM (SELECT ID FROM $wpdb->posts ORDER BY ID ASC) T WHERE NOT EXISTS (SELECT 1 FROM $wpdb->posts WHERE ID=T.ID-1) LIMIT 1");
$lastID++;
// I tried the following code but the it didn't work
$wpdb->query("ALTER TABLE $wpdb->posts AUTO_INCREMENT = $lastID");
}