I've been searching for hours, either for a plugin or some safe looking SQL to do this, but nothing seems to be exactly what I need...
I have a Wordpress site of approximately 32,000 posts, and we use various tags to help with administration on the back end (i.e. they're not visible on the front end or used for SEO, before anybody comments on too much usage of the same tag). About 30,000 of these posts include the tag 'new', but we need to now tag the remaining ~2,000 to match.
The WP administration panel isn't really up for the task - it would take somebody days to go through and apply a tag to 2,000 posts. Various plugins seem to exist but they don't really do what they claim in the descriptions. And the only SQL I could find that seemed helpful assumes that the tag is new and that I want to apply it to all posts in a single category. I suppose I could delete the existing tag (again, not a fun task with Wordpress' admin panel - it generally crashes after about 30 posts meaning somebody has to sit clicking the button over and over) and then run the SQL to apply a new.
Can somebody point me in the right direction please?
You could run a loop over all of your posts and use
wp_set_object_terms()
to add the desired tag:http://codex.wordpress.org/Function_Reference/wp_set_object_terms
I had this problem today too. I tagged all of my posts with the following SQL. (Replace
<prefix>
with your DB prefix and"GlobalTag"
with whatever you want your tag name to be.)NOTE: you may want to tweak the posts query in here. This tags all posts that are published and/or drafts and that have content that is longer than 15 words.