WordPress Reset AUTO_INCREMENT ID In Posts

July 22, 2014

wordpress

I've been testing a massive migration from a proprietary CMS to WordPress (using my WordPress C# client).

After about 20 different tests my post IDs in the WordPress MySQL database got out of control. I'd create 3,000 posts in one swoop and turn around and delete them while testing. This made my IDs something like 31,341 after day. This isn't a huge deal but it's annoying to me.

Note: If you already have created posts / pages and attached them to categories and then change the post id then they will no longer be related properly.

A quick google search will likely lead you to How to reset AUTO_INCREMENT in MySQL on Stackoverflow. However this won't work if you are running on the InnoDB engine. In my case I could just mass delete all the post with a SQL statement. If you have content and run the following commands bad stuff will happen.

I'd only use this if you don't care about dropping all your posts! USE ONLY IN LOCAL/DEV ENVIRONMENT

DELETE FROM wp_posts;
DELETE FROM wp_post_meta;
TRUNCATE TABLE wp_posts;
TRUNCATE TABLE wp_post_meta;