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?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
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.
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)