5

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.

6
  • why? ID is just a uniqque id and the value has no meaning Aug 14, 2018 at 15:16
  • ... and don't do development on production servers Aug 14, 2018 at 15:18
  • 1
    It's not on production. It's on a development server, who's database will soon be cloned into production. Aug 14, 2018 at 15:23
  • which make it exactlu like production Aug 14, 2018 at 16:45
  • 2
    Yes... my dev environment is exactly like my production environment. It makes debugging quite simple. As far as I know, most developers prefer to have similar prod/dev instances ;) Aug 14, 2018 at 20:06

3 Answers 3

3

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.

0
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.

1
  • You need to use wp_postmeta instead of wp_post_meta
    – clayRay
    Nov 21, 2022 at 0:57
1

ALTER TABLE table_name AUTO_INCREMENT = value

This SQL query fixed the issue for me.

1
  • What happens when you collide with a post id that already exists that is the next auto_increment value?
    – Sun
    Nov 7, 2022 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.