Part 2 of the previous Wordpress Tag Post
In my continuing effort to duplicate existing categories associated with posts as tags, I offer up this plugin. Remember, my goal is to phase categories out in favor of tags. So I don’t want to do just an abrupt change over switching my categories to tags. Instead, I want to duplicate them, and transition away from categories. First in the templates, then cleaned out of the database.
Here’s the process:
For each post, get a list of the categories. For each category, determine if the category (term_id), exists in the wp_term_taxonomy table. If it does, it will have the taxonomy of “post_tag”
Does the category already exist as a post_tag?
If Yes
Retrieve the term_taxonomy_id for that term, and insert it into wp_term_relationships. Also, update the count in the wp_term_taxonomy table for that post_tag - important for tag clouding.
No
Create a new record in the wp_term_taxonomy table referencing the same term_id but with a taxonomy of post_tag. Set the count to 1 on insert.
In either case:
Retrieve back the term_taxonomy_id, and insert that into wp_term_relationships for the post.
7 responses so far ↓
1 Wolfy // Mar 13, 2008 at 10:32 pm
Is there a plugin that lets you select tags from a list in wordpress the way you can select categories? Cause w/o that tags are kinda lame cause you end up duplicating tags i.e. “bike” and “bikes” etc…
2 Josh Kenzer // Mar 14, 2008 at 8:58 am
Yes, for the current WordPress version, the plugin is called Simple Tags (http://wordpress.org/extend/plugins/simple-tags) and it’s pretty awesome. However, in the next major release of WordPress, this functionality is built in.
3 Herr Rau // Mar 30, 2008 at 3:49 am
Thanks for the plugin, I’ve been looking for a way to switch to tags while keeping most categories, for similar reasons to yours.
A slight suggestion: In your plugin, you have hardcoded the database table prefix as “wp_” - my prefix is different, so I used the $wpdb->prefix variable instead to make it work.
(Actually, I did nothing of the sort. I just hardcoded *my* prefix, but really should have used the variable.)
Also, my installation is not in the root but in a folder, so to get the plugin to work I had to change the form action from:
“/wp-admin/plugins.php?page=copy_…”
to:
“plugins.php?page=copy_…”
to get it to work.
But now it works beautifully, thanks.
4 charlie // Mar 30, 2008 at 9:58 am
Hi there, thanks for the very useful plugin - I ran into the same problem as Herr Rau, above, but the problem was easily fixed. It should be just a matter of appending the bloginfo(’url’) function ahead of the form action and most users shouldn’t have a problem. Perhaps you could implement both that as well as the db prefix change for a future release.
I used to use UTW’s feature of automatically copying categories to tags as I selected them, but since version 2.3, I’d been neglectful in my tagging, so your plugin was great for getting me back on track. Thanks.
5 Josh Kenzer // Apr 9, 2008 at 7:04 pm
I’ve made both the changes that Herr and charlie suggested. I’ve uploaded the new zip file.
I also got the permissions to post it to extend.wordpress.org, so I will be doing that shortly.
6 Herr Rau // Apr 12, 2008 at 6:08 am
Works fine!
7 skiaddict // Jul 14, 2008 at 1:39 am
Doesn’t seem to work for posts that have multiple categories - appreciate the effort though!
Leave a Comment