4

I have one question. Will WordPress always assign new post post ID which is incremental n+?

For example if I delete some posts, will WordPress use ID of deleted post for new post added in future?

  • 1
    I'm not sure how WordPress handles it, but most software for forums, blogs, news sites and other similar sites do not delete content when you delete it. Instead, it's just marked in the database as deleted or disabled, but you can still find it in the database if you know where to look. This also means that the ID CANNOT be reused, because it's technically still in use. – Nzall Oct 3 '15 at 13:59
  • @NateKerkhofs When you first delete a post in WordPress, it is moved to the trash which like you described simply marks it as deleted but does not remove it from the database. When an item is deleted from trash it is purged from the database. – shea Oct 10 '15 at 7:55
7

Post ID is always incremental. There's no way the ID of a previous post is assigned to a new post. If a post is deleted, the ID of that post remains vacant forever.

| improve this answer | |
  • As wp create revisions also (if enabled), so if current post is one 1 next post id will be 3, in general. – Webloper Oct 7 '15 at 17:39
1

I think it's important to understand the why here. The post is stored in a database. 99% of databases that attach a numerical Id "automagically" to a new record do so via something called an "Identity" field (or column). This Identity increments at a fixed rate (usually by +1, but it can be other increments) each time a record is inserted into the database. Due to the way it functions internally, even if you delete the newest record, the one inserted after that will be greater than "the newest one that was just deleted". (Note that this is true for a hard delete and not just the kind of "soft delete" that was mentioned in the comments.)

There fore, the post id is unique by definition and will never be reused.

| improve this answer | |
0

The concept above is sound - but I was wondering is it the fact. So I looked at the ID column definition of the wp_post table in the database and it is marked as "AI" (meaning auto increment). This means the database is the implementation of the ID increment.

I think this means it will always be bigger than the previous value (typically +1) however in databases with linked tables there can be jumps - that was a non-technical meaning of "linked" - I recall an issue on oracle in an enterprise environment related to this but don't recall the details)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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