Renaming Custom Post Types and Taxonomies

I started developing a site with over a dozen custom post types. I’d like to rename a few of them, not just the display value, but the actual custom post type name. I’m worried however that by just running a SQL update query that I’ll miss some places where I need to change things or overwrite part of serialized data. I have already inputed over 3,000 items, so I can’t just restart with a clean database.

What would be the best way to rename a custom post type?
How about renaming a taxonomy?

Related posts

Leave a Reply

3 comments

  1. SQL query for renaming the posts:

    UPDATE  `wp_posts` SET  `post_type` =  '<new post type name>' WHERE  `post_type` = '<old post type name>';
    

    SQL query for renaming taxonomy:

    UPDATE  `wp_term_taxonomy` SET  `taxonomy` =  '<new taxonomy name>' WHERE  `taxonomy` = '<old taxonomy name>';
    

    That should take care of all of the database areas. Just remember to match the new names in the code where the post types or taxonomies are registered. As far as I know, this is not handled in any plugins yet.

  2. Hi @Derek Perkins:

    In general @John P Bloch’s answer is spot on but with a caveat. Plugins and even custom themes can and may store post type information and thus in order to be sure that you won’t corrupt your data you need to ensure your plugins and themes don’t store post types or if they do that you update their data as well.

    Can you tell us what plugins you are using?