How are Tags Implemented in Wordpress 2.3

by Josh Kenzer on February 28th, 2008

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.

  1. wp_terms
  2. wp_term_taxonomy
  3. wp_term_relationships
  1. 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.
  2. 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.
  3. 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:

Wordpress tag schema

Later, I will post the actual SQL/PHP code I use to duplicate my categories as tags. Stay tuned.

  • Wordpress is already in 2.52 but the biggest problem is that the hosting companies can't keep up.
  • Before you try installing different versions of word press, make sure you back up all posts. The one thing that is important would be the backing up of comments. You need to export it properly.
  • I just upgraded my Wordpress to 2.7 only to realize that many of the plugins don't work in 2.7 and I had to spend the last 2 days testing multiple plugins. It's really time consuming.
  • If you go to the official wordpress page, try clicking the plugins. There, you'll find the latest plugins that will work with the latest version of Wordpress.
  • I'm a wordpress fanatic. Thanks for your tips.
  • I've tried WP 2.7 and it's simply awesome.
  • When using WP 2.7 try using the official plugins recommended at the Official Wordpress plugin section.
  • 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.
  • Josh Kenzer
    Under Manage->Manage Tags (part of the simple tag plugin), do you see your numbered tags?
  • 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.
  • wordpress is truely an amazing platform for democratic expression.
  • Wordpress 2.7 is just the bomb. But make sure you have a back-up before installing the new version.
  • SEO
    Though Wordpress 2.3 is good but as soon as time passes, new innovations and enhancement in existing applications are very common and they are badly needed as well in this fast moving age.. Wordpress 2.7 has come up with great enhancements but do take care of your backs while upgrading your Wordpress..
  • Great article. Helps clear up a lot on the tagging confusing. You'll be surprise there are hell lot of people who doesn't know what tags are! :)
  • you are on my rss reader now
  • I always had problems upgrading word press.
  • Ben
    I have nofollowed all my tag links. Having a silo structure is way better for a blog.
    I can only advice people to do this.
blog comments powered by Disqus