Transferring categories to custom taxonomy

Let’s say that you have situation like myself few days ago. You have regular wp posts and categories with some tags in it. But you need a little more. More customization, more custom things that you simply can’t done through standard wordpress taxonomy (category & tags). So let’s say that you managed to fork you’re way through wp custom post types (CPT) and you assign some custom taxonomy (CT). As you know CT can be done “like tags” (‘hierarchical’ => false,) or “like categories” (‘hierarchical’ => true,). Now you wish to transfer your current “standard” categories to custom taxonomy with hierarchy.

Solution 1:

  • Find some appropriate plugin to do all hard work (I didn’t even bother with that ), or wait for me to create one 🙂

Solution 2:

  • When you create (register) CT with hierarchy ( codex ) with name like “genre”, open phpmyadmin on your server
  • Open your WordPress database
  • Paste SQL code in “SQL” tab under “Run SQL query/queries on database…
UPDATE wp_term_taxonomy SET taxonomy='genre' WHERE taxonomy='category'

Like you see, ‘genre’ stands for  custom taxonomy & “category” for old, standard categories.

Solution 3:

  • Open database name “wp_term_taxonomy”
  • Like you see inside that table you have all your current “standard” taxonomies like “category”, “post-tag”, “nav_menu”…
  • For each category you want to transfer to CT, click on “category” under “taxonomy” column
  • Rename “category” to your CT slug name (“genre” in our example) -> you assign slug name when you register custom taxonomy
  • That’s all 🙂

Same thing can be done with tags. For transferring standard posts to CPT you can refer to plugin like Convert Post Types which moves multiple posts based on category… or Post Type Switcher which is little simpler version with less options.

Advertisements

2 thoughts on “Transferring categories to custom taxonomy

  1. Just ran into a strange issue with using category instead of taxonomy for a custom post type… Had to switch all my cpt categories to taxonomies. Solution number three above was a life saver after searching for 30 minutes or so. Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s