I would like to migrate all the posts from my custom post type "cpt-project" to another existing custom post type named "cpt-publication".
I don't want to use any plugin to achieve it. I would prefer to use a SQL query through phpMyAdmin to make the migration but I don't find any info on how do it.
Thanks.
I would like to migrate all the posts from my custom post type "cpt-project" to another existing custom post type named "cpt-publication".
I don't want to use any plugin to achieve it. I would prefer to use a SQL query through phpMyAdmin to make the migration but I don't find any info on how do it.
Thanks.
WP CLI would be a better option. Assuming your host has it enabled, it shouldn't require installing any plugins.
wp post update $(wp post list --post_type=cpt-project) --post_type=cpt-publication
This searches for all posts of type cpt-project
and updates their post type to cpt-publication
.
The SQL answer:
UPDATE `wp_posts`
SET `post_type` = "cpt-publication"
WHERE `post_type` = "cpt-project"
This assumes your database table prefix is wp_
. It will change the post type directly in the posts table.
As @tom-j-novell stated in the comments to your question, doing it this way does not invalidate caches or fire any hooks. But depending on your usecase that might be exactly what you are after.