1

For a few days I've been after a filter or a function that creates more random ID's for posts like:

1920363522091 or Hpw_027991m-q

Instead of the wordpress pattern that is:

1, 2, 3, 4 ...

It can be in sequence too, but starting with a very high number that with time becomes indistinguishable.

I researched and researched but found nothing. Can someone help me?

4
  • This sounds like a bad idea. If the ID of a post is random, then there is a chance that posts will be given the same ID. The ID of a post is defined in the database as a incrementing key that must be unique. Commented Oct 6, 2017 at 22:15
  • @WizardCoder Yes, I thought the same, but I can avoid this by using timestamp or a sequence starting with a very high number. But I do not know which filter to use.
    – Iago Bruno
    Commented Oct 6, 2017 at 22:47
  • Look into this filter: wp_insert_post_data $data['ID']. Isn't this going to mess with the post sorting?
    – Ismail
    Commented Oct 6, 2017 at 23:01
  • Let's go on step back first. What is the actual goal behind this you're trying to achieve by doing this? I have the feeling that you're in the XY Problem trap meta.stackexchange.com/a/66378
    – kraftner
    Commented Oct 7, 2017 at 9:02

1 Answer 1

2

The post ID must be a number, it can't an alphanumeric string. The simplest way to force the use of the high numbers for ID's is to use phpMyAdmin, or some similar database management system, and edit the wp_posts table.

With phpMyAdmin:

  1. Open phpMyAdmin, open wp_posts table, and open Operations tab.
  2. Find AUTO_INCREMENT field, and change it to the number you want to use for your posts.
  3. Click Go to save the new value.

When the next post is created, it will use this value and will go from there. This doesn't affect previously created posts, and it is not a good idea to mess with them, there are many places where you need to make changes.

Check this out to see the max value allowed for BIGINT field (used for ID), but don't use the value close to the limit.

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.