How to reset the post ID increment

All we need is an easy explanation of the problem, so here it is.

So, after working on a script that imports tons of data from another API, and doing lots of testing, all new posts I make have a post ID above 10,000,000.

Thing is, now that I’m done, all my test data is gone, and my last “real” post has the ID 88.

Is there a method to “reset” my post ID’s, so that the next one I make has the ID 89? I know that there’s no real need to do this, but I plan on maintaining this site for many years and it’ll be annoying.

Worst case, I can just reinstall and export/import.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

I also happened to me once, I only had like 10 real post, so what I did was to go to phpMyAdmin, make sure your that on my wp_posts and wp_posts_meta tables are only information about the 10 real posts IDs, from the mysite/wp-admin/export.php I exported all the posts (10 of them), I run the following SQL query on phpMyAdmin.

DELETE FROM wp_posts;
DELETE FROM wp_post_meta;

TRUNCATE TABLE wp_posts;
TRUNCATE TABLE wp_post_meta;

And finally, I import again the 10 posts, after that the ID was bad to normally, mine was only around 10000 tho, but it should work nonetheless.

Method 2

there is another one way to reset the auto-increment id of wp_post_meta and wp_post table :
SOLUTION 1:

DELETE FROM wp_posts;
DELETE FROM wp_post_meta;

Delete record by delete command but it will not reset the increment ID. Hence after deleting the record from both table rest the increment id like below command.

ALTER TABLE wp_posts AUTO_INCREMENT = 1;
ALTER TABLE wp_post_meta AUTO_INCREMENT = 1;

SOLUTION 2:

TRUNCATE TABLE wp_posts;
   TRUNCATE TABLE wp_post_meta;

Truncate record by Truncate command then it will reset the increment ID value to 0 and delete the records.

Method 3

ALTER TABLE table_name AUTO_INCREMENT = value

This SQL query fixed the issue for me.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply