Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
A follow-up question in the same vein is regarding custom .htaccess rewrite rules. Will there be a lot of leftover rules clogging up my database? I haven't launched the site yet, so I don't need any of the old links to be redirected. –  Derek Perkins Sep 1 '10 at 5:43

3 Answers 3

up vote 21 down vote accepted

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.

share|improve this answer
    
Thanks, that's exactly what I was looking for. –  Derek Perkins Sep 1 '10 at 5:45
3  
Excellent answer, exactly what I needed. Here's a tip in case others hit the same problem as I did: After I ran the query and updated my code, things were basically working but when I tried going to the page for an individual content item I got a 404 error. I think some permalink cache needed to be reset; I went to Tools > Permalinks and clicked Save, then the detailed pages started working. –  Andy Giesler Mar 11 '11 at 20:06
    
Awesome this (with Andy's hint) made this a cinch. –  Zach L Oct 31 '11 at 14:41
    
When I did this, I updated the guid field as well. This might help make it unnecessary to regenerate permalinks as @AndyGiesler mentioned. Just include the following in your UPDATE statement: guid=REPLACE(guid, '<old post type name>', '<new post type name>') –  rinogo Mar 1 '13 at 20:44
    
Just to add a little more info to rinogo's comment, this is a little safer way to update the guid: UPDATE wp_posts SET guid = REPLACE (guid, 'post_type=<old post type name>', 'post_type=<new post type name>'); –  David Feb 13 at 5:49

If you don't want to have to perform the SQL queries yourself manual there are a couple of plugins you can use:

I've successfully used Convert Post Types to mass change posts.

For converting invididual posts then Post Type Switcher is a better option.

share|improve this answer
    
Thanks for posting those links. I'm fine running the SQL queries myself, but those will definitely come in handy for others that come across this posting. –  Derek Perkins Sep 1 '10 at 5:24

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?

share|improve this answer
    
That's a good point. I'm building my theme custom, so I'll definitely have to go through and change my code around. I don't have any plugins that are storing custom post type info however. –  Derek Perkins Sep 1 '10 at 5:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.