If you’ve been running a multi-author blog like us, over a period of time, you’ll see your list of tags growing exponentially. When I reviewed the number of tags on Techtites today, I noticed that this was well over 1,100 tags!

So, I went into the Tags interface and immediately realised that I’m going to spend an hour just deleting and cleaning up tags.

There are a few WordPress plugins available that allow you to manage tags and categories, including Term Management Tools. However, there isn’t a good free plugin to delete and clean up tags.

So, with a bit of googling, I came across SumTips post. If you have access to your database via phpMyAdmin or a similar tool then it will take you less than a minute to delete unused or unpopular tags.

If you proceed beyond this step, please be extremely careful. Playing with your database table is risky and can break your entire site!

Step 1: Backup your database

This is an extremely important step. Before proceeding to make any changes to the database, make sure you have backed up your database.

Step 2: Run this query in phpMyAdmin

Power up your phpMyAdmin and head over the the SQL tab and enter the query below to delete all unused tags (line 1) and remove any relationships that have been lost as a result of the deletion (line 2).

Delete Tags

[sql]
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count = 0 );
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);
[/sql]

In my case, all the tags were used at least once, and so the query didn’t delete any tags. I decided to remove any tags that were used less than three times and so modified the same based like that in the screenshot above.

[sql]
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count < 3 );
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);
[/sql]

This query deleted over 700 tags and now I’m left with a much smaller number of tags.

You can change 3 above to any other number that you’re comfortable with.

Step 2: Optimise your table

When you’re done deleting the tags, this will create a lot of overhead. Remember to optimise your database tables when you’re done.

(Visited 1,894 times, 1 visits today)
Advertisements