Skip Navigation

[Resolved] Changing one post type to another

This thread is resolved. Here is a description of the problem and solution.

Problem:
I'm trying to change the post type of several posts. From Activities cpt to Destinations cpt. I tired to bulk change them using the Post Type Switcher plugin. I get a WPML related error, which I described here: https://wpml.org/forums/topic/wpml-error-during-changing-post-type-of-posts/

Solution:
In WordPress databases, all posts are stored in the posts table which is usually prefixed by wp_ (wp_posts table), the post type for each post is stored in the column post_type. Check more about the WordPress tables here https://codex.wordpress.org/Database_Description

That's what the "Post Type Switcher" plugin does, it changes the value of the column for each post in the source post type to the destination post type.

WPML uses the default WordPress databases for storing content and translations but uses some new tables to for storing relations/links between original and translated content. Shekhar has shared a link to WPML database documentation https://wpml.org/documentation/support/wpml-tables/

When you have changed the post types for your posts, WPML was not able to build an inconsistent state between the updated records in default WordPress table(wp_posts) and the translation links in WPML table(icl_translations, column element_type)

As there is no plugin that can switch the post type in WPML tables, you will have to change that in database level using SQL queries. This is an advanced level of technical skills, so If you are not comfortable with coding, consider hiring a developer one of our partners too, check here https://toolset.com/contractors/

I can also imagine another way, which will involve using a paid plugin(WP All Import/WP All Export). We can export all Activities and then import them as if they were Destinations. Check the following tutorials from WPML that explains how to export/import WPML translated contents.

The user fixed the issue in database level with the following SQL queries:

UPDATE  `wp_posts` SET  `post_type` =  'newcpt' WHERE  `post_type` = 'oldcpt';

UPDATE `wp_icl_translations` SET `element_type` = 'post_newcpt' WHERE `element_type` = 'post_oldcpt'

Relevant Documentation:
https://wpml.org/documentation/support/wpml-tables/

https://wpml.org/documentation/plugins-compatibility/export-multilingual-websites-using-wp-all-export-wpml/

https://wpml.org/documentation/related-projects/wpml-all-import-plugin-website-import-with-wpml/

This support ticket is created 3 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by jozsefG 3 years, 10 months ago.

Assisted by: Jamal.

Author
Posts
#1648619

Hello
I'm trying to change the post type of several posts. From Activities cpt to Destinations cpt. I tired to bulk change them using the Post Type Switcher plugin. I get a WPML related error, which I described here: https://wpml.org/forums/topic/wpml-error-during-changing-post-type-of-posts/. I'd got practically no support from WPML about this. I have 4 languages set in WPML. When I tried it one by one at the beginning it seemd to work, but at bulk changing it went crazy. After that even if I tried to change manually one by one the posts simpy disappeared.

Is there a good way to change the post type of a given post when that content is translated?

The content is restored now to the pre error state. Activities CPT has a taxonomy linked to it that Destinations don't have, but I can delete that.

#1648951

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

I believe it was just a misunderstanding with Shekhar from the WPML support team. He did mention that you will need to update some custom tables, and that is a bit tricky and must be done by a professional coder, that's why he suggested contacting a known contractor.

In WordPress databases, all posts are stored in the posts table which is usually prefixed by wp_ (wp_posts table), the post type for each post is stored in the column post_type. Check more about the WordPress tables here https://codex.wordpress.org/Database_Description

That's what the "Post Type Switcher" plugin does, it changes the value of the column for each post in the source post type to the destination post type.

WPML uses the default WordPress databases for storing content and translations but uses some new tables to for storing relations/links between original and translated content. Shekhar has shared a link to WPML database documentation https://wpml.org/documentation/support/wpml-tables/

When you have changed the post types for your posts, WPML was not able to build an inconsistent state between the updated records in default WordPress table(wp_posts) and the translation links in WPML table(icl_translations, column element_type)

As there is no plugin that can switch the post type in WPML tables, you will have to change that in database level using SQL queries. This is an advanced level of technical skills, so If you are not comfortable with coding, I will also suggest contacting one of our partners too, check here https://toolset.com/contractors/

This does not mean, that I do not want to help. We are here to help as long as it is within our scope of support. Please ask any question about our products(WPML included) and we'll help.

I can also imagine another way, which will involve using a paid plugin(WP All Import/WP All Export). We can export all Activities and then import them as if they were Destinations. Check the following tutorials from WPML that explains how to export/import WPML translated contents:
- https://wpml.org/documentation/plugins-compatibility/export-multilingual-websites-using-wp-all-export-wpml/
- https://wpml.org/documentation/related-projects/wpml-all-import-plugin-website-import-with-wpml/

I hope this helps. Let me know if you have any questions or doubts, we'll do our best to help 🙂

#1650225

Thank you Jamal for your explanation.

The export-import is a very good idea but it was much easier to just update the database with queries. I will post here the solution, maybe somebody will benefit from that when browsing for the same solution.

I had to update two tables: wp_posts and icl_translations, as you told me.

 
UPDATE  `wp_posts` SET  `post_type` =  'newcpt' WHERE  `post_type` = 'oldcpt';
 
UPDATE `wp_icl_translations` SET `element_type` = 'post_newcpt' WHERE `element_type` = 'post_oldcpt' 

Element type column contains the post type slug with a post_ prefix.

I guess I could have make a complex query for updating both tables at once, but this was quicker and easier like this because I am not a database expert. But this is really just basic SQL.

Now everything works as expected, translations are linked correctly and working without problem.

#1650327

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

That's awesome and thank you for sharing the solution. I am glad, I could be of help.

Finally, I'll have to kindly ask you to mark this ticket as resolved and open a new ticket for any other question or request.

#1650329

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.