• Whether I am creating a new post, a new page or a new custom post type, the ID counter increments by 1 each time, regardless of the content type for the objects I mentioned.

    Same goes to creating a new post tag, or a custom taxonomy. Creating a new category will increment the ID counter by 1 and that will affect the ID of a newly created tag.

    However, creating a taxonomy of some sort, would not affect the ID counter of posts.

    So my question is, how many ID counters does WP uses and what content each of them monitors?

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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.

    Thread Starter rechazame

    (@rechazame)

    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.

    Thread Starter rechazame

    (@rechazame)

    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘What WP contents share the same ID incrementing?’ is closed to new replies.