As soon as Wordpress rolled out tagging in 2.3, I was done with categories. To me, categories feel so confining. I want to tag posts as I need to and not add full categories about something I only post about once or twice. Wordpress also rolled out a tool under categories to convert categories to tags. However, I get a fair amount of traffic to some of my category pages, so I don’t want to convert categories to tags, I want to duplicate them. Then I can hide the categories from the templates in favor of tags but still maintain those category pages for older content.
In order to copy categories to tags, I need to better understand how tagging is done in the database. There are three Wordpress tables that make up categories and tags. These tables also contain the names of your blog roll categories.
- wp_terms
- wp_term_taxonomy
- wp_term_relationships
- wp_terms: This table stores the actual category or tag name. It also stores the slug (the name used in the URL for category and tag pages). The slug is usually the lower case version of the tag with spaces replaced by dashes. There is also a term group field. I’m not sure how/where this is used.
- wp_term_taxonomy: This table defines if the term is a category, post_tag or link_category. For each item in your wp_terms table, there is an entry in the wp_term_taxonomy table. However, there may be multiple references to the wp_terms table. For example if you have category, tag and blogroll category named Internet, there will be one entry for Internet in the wp_terms table and three entries in the wp_term_taxonomy table. Also, if a category is a child category of another category, the parent category is stored in this table. The id stored in the parent category references the wp_term’s term_id, not the term_taxonomy_id - so it’s not exactly a recursive table.
- wp_term_relationships: This simple two column table maps the terms in wp_terms to the object - i.e. the blog post.
Here is a simple ERD of the relationships:

Later, I will post the actual SQL/PHP code I use to duplicate my categories as tags. Stay tuned.
5 responses so far ↓
1 Cynthia Blue // Mar 4, 2008 at 7:21 pm
Just found this post via google… when I upgraded to 2.3 I mistakenly chose for WP to automatically convert my categories to tags. Well.. now I have tags that are numbers (23, 43, 45 etc) in the database. And I’m not sure how to clean these out. I don’t want to mess up the relationships. Using the Simple Tags plugin, they don’t show in my tag cloud, but when I use the default Tag Cloud they do show.
2 Josh Kenzer // Mar 5, 2008 at 9:23 pm
Under Manage->Manage Tags (part of the simple tag plugin), do you see your numbered tags?
3 Cynthia Blue // Mar 5, 2008 at 9:57 pm
I do see the numbered tags… I installed Simple Tags the Plugin and it has helped. However, it doesn’t automatically assign tags for untagged posts like it says it does.
4 Copy Categories to Tags - The Plugin // Mar 7, 2008 at 3:08 pm
[...] Part 2 of the previous Wordpress Tag Post [...]
5 On Tags and Categories - IT Crossing Blog // May 2, 2008 at 9:42 am
[...] a third post, Rip links to another blog entry which highlights how keywords1 and categories are implemented in WordPress 2.3. This really [...]
Leave a Comment