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?

3

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.

Leave a Comment