I have a WordPress site that I just updated to 3.1. I want to make use of custom post types now, my question is how can I assign (transfer?) a post to a newly created custom post type ?
For example, all my articles (news, poems, ideas to change the world) are in Posts. Now I have created the custom post types News, Poems, etc. and I want to transfer my old posts to these new custom post types.
I hope this is clear enough, anybody ?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
It seems that the easiest way is to do it manually in the DB. If you don’t have access to the DB, or if you don’t want to do it manually, you can install a plugin that will do it one post at a time, or a plugin that will bulk convert a lot of posts at once
Method 2
there is a great plugin Post Type Switcher
that gives you simple way to change a post type in WordPress.
Method 3
For those who are looking for a code solution:
$post_id = 123; // Set this to the ID of the post you want to update. $post_obj = get_post( $post_id ); $post_obj->post_type = 'custom-post-type'; // Set this to the slug of your custom post type. wp_update_post( $post_obj );
Method 4
You can use “Convert Post Type” to convert from your categories to custom post types that you have already defined.
This plugin will convert all your selected categories to a custom post type that you can choose.
Method 5
This query will convert all posts to a different post type. You need to make sure that both the previous and new post types share the same categories and taxonomies when you register it with register_post_type.
UPDATE `wp_posts` SET `post_type` = 'blog' WHERE `post_type` = 'post';
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0