Tags are back

Took a bit of work, but tags are back up! I was originally (2005) using Felix Wong’s plugin, but it hasn’t been updated yet. So I installed the latest (and *final*, sob!) version of [Ultimate Tag Warrior](http://www.neato.co.nz/archives/2007/06/30/ultimate-tag-warrior-fin-the-end/) by Christine Davis. UTW looks awesome from what I’ve seen so far.

So now I’ve got several hundred old posts with obsolete tags, and a fancy new tag engine. I took a look at some of Felix’s tag code, had a look at the database table(s) he was using, and figured out how he was storing tags. UTW has a slick little import/export feature for tags, but it only writes/saves tags in custom fields. (Edit one of your posts and look down near the bottom of the page for the “Custom Fields” section.) After figuring out how WordPress stores these custom fields in the database, I was ready to try and copy my old tags into “custom fields”, from which I would be able to import them into UTW.

The only difficulty I had was gathering multiple tags into a single custom field–Felix’s system created a separate row in the database for each tag on each post, whereas UTW’s import process wants *all* tags for one post in a single custom field. A little digging in the [MySQL 4.1 manual](http://dev.mysql.com/doc/refman/4.1/en/index.html) gave me the answer: the [GROUP\_CONCAT](http://dev.mysql.com/doc/refman/4.1/en/group-by-functions.html#function_group-concat) aggregating function. I wrote the following query to gather all the old tags (from table ‘sc\_tags\_items’) and place them as a comma-separated list into a ‘UTW\_tags’ custom field for each post:

insert into sc_postmeta (post_id,meta_key,meta_value)
select post_id
, ‘UTW_tags’
, group_concat(tag_name separator ‘,’)
from sc_tags_items
group by post_id;

After that, all I needed to do was tell UTW (on the admin interface go to Manage / Tags) the name of the custom field and what the separator was, then click the “Import from Custom Field” button. I got a few errors, probably from odd characters in some of my old tags, but it looks like all (or nearly all) of my tags are back. I fiddled around trying to find what might have caused the errors, but after an hour or so I’ve given that up as a bad job. So as soon as I finish this post, I’ll restore my “/remodel” link to redirect as it was intended to.

About Jim Vanderveen

I'm a bit of a Renaissance man, with far too many hobbies for my free time! But more important than any hobby is my family. My proudest accomplishment has been raising some great kids! And somehow convincing my wife to put up with me since 1988. ;)
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *