Reset Post IDs to less than 64bit integer

This answer is the way I would take to solve the issue if I had to face it, it means is not the answer but one of the possibilities.

All the operations I will suggest should be run on a development/local server on a backup of database and not on production nor on original database.

If you have 26,000 posts but post id like 4,863,166,253 there are zillions of ids that are not used.

To solve this issue you need to:

Step 1

  • remove unused post ids. (trashed posts, revisions)
  • removed orphans post meta entries
  • remove orphans taxonomy relation entries

There are plugins for the scope, but it can be done using simple raw SQL queries.

Step 2

Reset post ids changing them to start back from 1. This can be done using a combination of PHP + MySQL: if you retrieve post id column as an array (e.g. via $wpdb->get_col()), array keys (incremented by 1) would be new posts ids for posts whose current id is in array values.

Note that posts ids have to be changed in:

  • post table
  • taxonomy relation table
  • post meta table

I suggest you run such a routine on subsets of posts using paginated results and not on thousands of rows at a whole.

Step 3

Set the AUTO_INCREMENT index on post table to post count + 1.

Done

At the end of this process you higher post id should be easily inside the 32bit integer limit.

Prevent post limit is reached again

  • Disable post revisions or limit it in number (see Codex).

  • Move older posts (2 years old? 5?) to a separate blog on a multisite environment, e.g. site1-archive.example.com for posts in site1.example.com.

    This can be done using WordPress exporter with date range option.

    If you plan to do this, is way better if done before resetting post ids (step #2 above), in this way both 2 blogs can have a lower post id.

    Of course after that you should also put in place a way to redirect archived post urls to new urls.

Leave a Comment