WordPress tags

One can find quite a few tag-related plug-ins for the WordPress, but adding tags to your old posts may prove to be quite a tedious task. Here is a simple method of adding tags to old posts, but this one is not for faint hearts—you have to run a SQL statement against the database.

Before you start

Back-up the database, better safe than sorry.


The following technique works only if the table wp_term_taxonomy has not been modified by a weird plug-in or manually; columns term_taxonomy_id and term_id should contain same numbers. To verify this, run the following:

SELECT COUNT(`term_taxonomy_id`)
    FROM `wp_term_taxonomy` 
WHERE `term_taxonomy_id` != `term_id`;

The result should be 0. If the returned result is greater than 0, do not use this procedure.

Step 1

In the Manage–>Tags list, note IDs of your tags. Float the mouse pointer above the tag name to see the  “ID” displayed in the status bar of your browser. For example, some of my tags:

ID Tag name
12 data collection
13 six sigma
14 standard deviation
18 database

Step 2

Note IDs of your posts; floating the mouse pointer above a post name displays the “ID” in the status bar of the browser.

Step 3

Create a table of associations between post and tag IDs.

Suppose we want to add tags “database” (id=18) and “data collection” (id=12) to the post Basic database checkup (id=95); tags “six sigma” (id=13) and “standard deviation” (id=14) to the post Mathematician with no diploma (id=45).
The table would look like this:

Post ID Tag ID
95 18
95 12
45 13
45 14

Step 4

Based on the previous table, add rows to the wp_term_relationships using the code snippet. If you have more rows just follow the pattern below the “VALUES” keyword. The third number within parentheses is always 0.

INSERT INTO `wp_term_relationships` 
    (`object_id`, `term_taxonomy_id`, `term_order`)
    (95, 18, 0),
    (95, 12, 0),
    (45, 13, 0),
    (45, 14, 0);

Worked nice for me on WordPress 2.5.1.