Nelio's blog

Latest News and Updates in Nelio's World

WP Database Snippet: From categories to tags (and vice versa) with a single SQL update

bloated CMS databaseAfter the how to transform posts to pages topic, the other question we get all the time from our customers is how they can transform categories into tags and the other way round.

If you just want to transform a few, the simplest way to do this is for sure from your dashboard (installing the Categories to Tags converter available in the tools submenu, it has not been updated in more than 2 yrs but should still work fine).

But if you need to transform many of them, a direct database update will be the fastest way. In fact, a single SQL sentence will suffice to perform this “magic”

UPDATE wp_term_taxonomy SET taxonomy='post_tag', parent=0 WHERE taxonomy='category'

where the parent column needs to be set to zero since tags cannot be organized in hierarchies so they cannot have a parent (while categories can). To convert tags to categories just use the same sentence but reversing the literals to use for the taxonomy column.

WARNING: I don’t think I need to remind you that before any modification to your WordPress site/database you should create a backup, do I? If you make a mistake and transform what should not have been transformed, the backup will save your life!

For more about WordPress, web and social media news check us on twitter , facebook or subscribe to our blog feed or mailing list .

Be sociable, share!

Nelio SoftwareWP Database Snippet: From categories to tags (and vice versa) with a single SQL update
Share this post


Join the conversation

Join the conversation