Moderator
James Huff
(@macmanx)
Volunteer Moderator
Post slugs share the same table in the database, that’s the part of the URL that’s the post title, so example.com/2015/02/this-is-the-post-slug.
If you have a second post titled This Is The Post Slug, you’ll wind up with example.com/2015/02/this-is-the-post-slug-2.
Categories and tags also share table in the database, so if you create This category, its slug will be example.com/category/this, and if you later make This tag, its slug will be example.com/tag/this-2.
I was actually interested in understanding the way an ID (not a slug) is given to a post or a taxonomy when they are created.
For example:
1. Create a post of type post
. A post is created with an ID of 8.
2. Create a post of type page
. A post is created with an ID of 9.
3. Create a tag. A tag is created with an ID of 32.
4. Create a category. A category is created with an ID of 33.
5. Create a post of type book
(a custom post type). A post is created with an ID of 10.
There you can see how the ID given to all post types is incremented with each creation of a post regardless of its type. However, the incrementation does not affect the ID given to a newly created taxonomy.
My question was what content share the same ID pool in WordPress? I am looking for a more extensive information than the one I have after performing the test I gave example of.
I think you are over analyzing this. The IDs are just the primary index of the entry in the database. It is basically the row id of the table. WordPress itself doesn’t do any incrementing.
All post types share the same table (wp_posts) and all terms share the same table (wp_terms). You can just look in the database if you want to see what objects are stored where and see where the IDs come from.
Out of curiosity, what is the reason for looking in to this issue?
Moderator
James Huff
(@macmanx)
Volunteer Moderator
Posts and Pages share the same ID pool, and Categories and Tags share the same ID pool.
Beyond that, other things may share ID pools depending on plugins and how they’re configured.
Edit: On the specifics, csloisel is correct, it’s all about the row ID in the specific table.
Then I guess I will get my answers from the database… Sounds right. Thanks for the advice cslosel 🙂
And about the reason, yes, it is a bit strange to get into these details like that but I am doing it bc I wanted a collision proof way of assigning unique meaningless slugs to all posts and all terms regardless of their type. For example, I thought about generating a hash from a post ID and use that hash as the post slug. This way the slug is unique as there are no other ID numbers the same as this.
However, in spite of all that research, I ended up using a random 15 digit numbers as slugs and regenerate them if slug exist validation fails 😀
Btw, any feedback about the approaches mentioned is welcome.
Moderator
James Huff
(@macmanx)
Volunteer Moderator
You’re welcome! Random is indeed a way to go, you may wind up wit one collision at some point though, unless your random pool is built to preclude existing slugs.