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!

This entry was posted in database, technical details. Bookmark the permalink.

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

  1. Pingback: Wordpress posts pages SQL | Wiki 42

  2. Pingback: SQL query to turn categories into tags (and vice versa)

  3. Pingback: SQL query to turn categories into tags (and vice versa) | Start a Web Design Company

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>