• Resolved matsdagerlind

    (@matsdagerlind)


    After running my blog a while, adding and removing categories, the category numbers are all over the place. I like to renumber/reset them.

    I the old days you could do as described here:

    Renumbering Categories in WordPress Blogs

    but since v2.3 this is no longer valid information, i.e:

    UPDATE wp_categories SET cat_ID=2 WHERE cat_ID=3 LIMIT 1;
    UPDATE wp_post2cat SET category_id=2 WHERE category_id=3;

    doesn’t work since the wp_categories and wp_post2cat tables are no longer used.

    After studying the new database structure in phpMyAdmin, I came up with this:

    UPDATE wp_terms SET term_ID=2 WHERE term_ID=3 LIMIT 1;
    UPDATE wp_posts SET post_category=2 WHERE post_category=3;

    No luck. The first SQL command seems to work, but not the second.

    A closer look at the wp_posts table reveals that the post_catagory field doesn’t in fact seem to be used for the obvious, i.e. storing information about which category a post belongs to. This seems a bit strange, but even stranger is that I can’t seem to find this information in any field anywhere.

    I don’t know anything about sql really, so I’m just trying to apply general logic here. I bet there is someone in the WordPress community that can sort this out for me.

    Thanks in advance,
    /Mats

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter matsdagerlind

    (@matsdagerlind)

    BUMP

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    post_category is deprecated and not used anymore. It’s a holdover from the older stuff.

    Frankly, renumbering these things is a massive pain with no benefit, so I recommend not doing it at all. However, if you’re totally OCD and just have to do it…

    wp_posts holds the posts, obviously. Every post has an ID number.

    wp_terms holds the “terms”, which are basically just words. Names and slugs.

    wp_term_taxonomy assigns meanings to those terms. This is what associates a term with what it actually is, like a Category or a tag or a link category. Every term is associated to a taxonomy with a unique term_taxonomy_id.

    wp_term_relationships associates the items (posts in this case) to a taxonomy.

    So, if you’re renumbering a term, you need to fix its associated taxonomy as well, so that it knows about it. Look in the wp_term_taxonomy table for the term_id number, where the taxonomy=’category’ as well. Then change that term_id number to be your new term_id number.

    Since you won’t be changing the term_taxonomy_id, you should not have to do anything with the wp_term_relationships table.

    Thread Starter matsdagerlind

    (@matsdagerlind)

    Thanks Otto. I still have to digest what it is you’re really saying here, but I have a feeling that when I have done so, I will be able to do what I set out to do – or make an informed desicion not to do it.

    So I’m changing the status to ‘resolved’ for this question.

    /Mats

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Renumber categories?’ is closed to new replies.