7

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 ?

1

6 Answers 6

12

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

0
4

there is a great plugin Post Type Switcher that gives you simple way to change a post type in WordPress.

4

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 );    
1
  • What about the extra data that comes with the post? For example the metadata and taxonomies?
    – Joop
    Commented Nov 24, 2021 at 12:24
3

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.

0

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';
-1

You can try this plugin, it simply does the job.

1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – vancoder
    Commented Aug 3, 2022 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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