Convert Certain Tags to Categories / Delete Certain Tags using SQL

ATTENTION! Do not follow this advice! It is of no use, now that I found the converter for Tags ↔ Categories: Categories to Tags Converter Importer!!!

Sometimes you give posts a tag but realize later it should rather be a category.

What you can do to convert a certain tag – in this post we assume it is Ubuntu 10.04 – to a category?

Remember to back up your WordPress installation first! The following procedures worked for me but I cannot guarantee it'll work for you too!

  1. Add the category to the posts
    Go to the WordPress administration panel and click on "Posts". Find one that has the tag to convert and click on the tag to display all posts with this tag. This is somehow tedious as you should not select all at once (in my installation I select 20 at a time). Otherwise it will be too slow. So you select about 20 of them and choose the bulk option Edit. Add the Category you want to assign and Update. Repeat the step until you have assigned the category to all posts with the tag.

  2. Delete the unneeded tag assignment
    This is the tricky part as it is not possible directly via the WordPress admin user interface. So we user SQL commands to get the job done.

The following SQL statement – similiar to the one I found to delete all tags of a WordPress installation on this website – searches for all assignments of the Tag Ubuntu 10.04 to posts on the blog and deletes the assignment.

DELETE b
FROM
    usr_web0_1.wp_terms AS a
    LEFT JOIN usr_web0_1.wp_term_taxonomy AS c ON a.term_id = c.term_id
    LEFT JOIN usr_web0_1.wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE (
    c.taxonomy = 'post_tag' AND
    a.name = 'Ubuntu 10.04'
    )

Comments