In moving my blog across from WordPress.com, I decided I wanted to review all of the posts that I imported. To track which ones I had done and which ones I had not, I created a tag to apply to all of the posts. Then, the challenge was to apply that tag to all of the posts. I couldn’t find anything on the front end, so I decided to try the database.
Here are my explorations in applying that tag:
First, here is the SQL that displays my new tag. The slug (URL-friendly version of the name) of my new tag is “tomove”. So, this SQL displays the ids for that slug:
select a.term_id, a.name, a.slug, b.term_taxonomy_id
from wp_terms a, wp_term_taxonomy b
where a.term_id = b.term_id
and b.taxonomy = 'post_tag'
and a.slug = 'tomove'
insert into wp_term_relationships (object_id, term_taxonomy_id, term_order)select c.id object_id, b.term_taxonomy_id term_taxonomy_id, 0 term_orderfrom wp_terms a, wp_term_taxonomy b, wp_posts cwhere a.term_id = b.term_idand b.taxonomy = 'post_tag'and a.slug = 'tomove'and c.post_type = 'post'and c.post_status = 'publish'