WordPress.org

Ready to get started?Download WordPress

Forums

Clean up category IDs? (9 posts)

  1. Agent D
    Member
    Posted 4 years ago #

    Hi,

    By mistake I deleted a bunch of categories (ID=12,13,14,15,16) from dashboard, so re-created them. The problem is that now the ID starts from 17, which means that the deleted category ID numbers are unusable anymore?? I have many customized page templates and since they are called in based on the ID number it's a bit pain for me to go back and change the php code everytime something like this happens... Any idea how I can re-use those ID numbers? Many thanks!

    AD

  2. stvwlf
    Member
    Posted 4 years ago #

    The simple answer is, you can't.

    Unless you restore your database back to where it was before you deleted them.

    Or find every reference in the database to a current cat ID and replace it with the old ID.

    Or can find a plugin that change cat ID's. (I don't know if there is one but there could be.

    Those cat ID's are stored in a number of places on every transaction involving them, and if you miss one when you change, you will make a mess that will not be fun to clean up.

    So, to revise my original statement, if you get educated on all the places that use the cat ID you can change them. But otherwise you are better off leaving them alone.

  3. Mark / t31os
    Moderator
    Posted 4 years ago #

    You could just re-set (not reset) the auto-increment for that table, it won't do any harm, unless you've already started creating new categories that you can't afford to lose..

    IE, if you have ...

    5
    6
    7
    8
    12
    13
    14

    Then it's not an option..

    If that's not the case, post back and i'll provide a line of SQL you run from PHPMYADMIN that will set the auto-increment back for you.

    I recently flushed out all my categories, so set mine back to 1... :) Now i have nicely numbered 1,2,3,4 ids etc..

  4. Agent D
    Member
    Posted 4 years ago #

    Hmm... interesting. Thanks for your suggestions. I think I'm going to just leave as it is. Many thanks. AD

  5. Michael Bishop

    Posted 4 years ago #

    Note also that as of 2.9, you can use category slugs in your category templates instead of IDs.

  6. Mark / t31os
    Moderator
    Posted 4 years ago #

    miklb are you referring to new support for using category slugs inside functions such as is_category, and in_category?

    If that's the case, it certainly makes usage a bit easier... good stuff.. :)

  7. Michael Bishop

    Posted 4 years ago #

    I was actually referring to the fact that you can now have template files for categories using the slug instead of just the ID.

  8. chartinael
    Member
    Posted 4 years ago #

    is that why cats and tags cannot have identical slugs anymore ... annoys me to death.

  9. Mark / t31os
    Moderator
    Posted 4 years ago #

    I was actually referring to the fact that you can now have template files for categories using the slug instead of just the ID.

    Oh i see, like category-name.php , instead of having to use category-ID.php ... :) Still useful... :)

Topic Closed

This topic has been closed to new replies.

About this Topic