Skip Navigation

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

Problem:
The client is attempting to convert posts into custom post types (CPT) based on their categories, ensuring that translations remain attached and old permalinks redirect to the new ones. They encountered issues where not all translations transferred during the migration using WPCLI.
Solution:
We recommend disabling the WPML plugin initially to ensure all posts are correctly converted to the new CPT without language complications. Once this is done, re-enable WPML and manually connect the posts as translations. This can be done either through the WPML interface or programmatically using the

wpml_set_element_language_details

hook. Detailed guidance on linking translations can be found here: https://wpml.org/faq/how-to-link-already-translated-pages/
and the hook documentation here: https://wpml.org/wpml-hook/wpml_set_element_language_details/
If custom coding is required, we suggest hiring a WPML contractor from https://wpml.org/contractors/

Please note that this solution might be outdated or not applicable to your specific case. We highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket for further assistance.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 3 replies, has 0 voices.

Last updated by Dražen Duvnjak 2 weeks, 3 days ago.

Assisted by: Dražen Duvnjak.

Author Posts
November 1, 2024 at 3:49 pm #16355568

Will Macowski

Background of the issue:
We are trying to convert posts into custom post types based on their categories, optionally mapping certain categories and tags to new terms in new taxonomies associated with the new post types. For example, all 'blog' category posts become the 'Article' post type, and if they have the post tag 'ipv-therapy', they are assigned to the new 'Product Line' taxonomy term of 'ipv'. We need to ensure all translations attached to posts also convert and stay attached. We need to ensure the old permalinks are redirected to the new permalinks, in case users have bookmarks or links in emails, etc. We have tried some export/import plugins, post type switcher, and then our own WPCLI function. We have some success migrating the original posts, but not all translations transfer along with them. We are able to provide our CLI code if needed.

Symptoms:
Not all translations transfer along with the original posts during migration.

Questions:
How do we effectively convert posts to custom posts along with translations?
How can we ensure all translations attached to posts convert and stay attached?
How can we ensure the old permalinks are redirected to the new permalinks?

November 6, 2024 at 8:07 am #16369980

Dražen Duvnjak
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

thanks for contacting us.

What I suggest first is to disable WPML plugin, and make sure that all posts are correctly converted to your new CPT. When WPML is disabled they will all appear in the same language.

After that, you can enable WPML and need to connect posts as translation manually (https://wpml.org/faq/how-to-link-already-translated-pages/) or via code using our hook wpml_set_element_language_details

- https://wpml.org/wpml-hook/wpml_set_element_language_details/

If you need help with custom coding we suggest hiring a WPML contractor: https://wpml.org/contractors/

Hope this helps.

Regards,
Drazen

November 11, 2024 at 4:37 pm #16389710

Will Macowski

We're still struggling with using the WP CLI to query posts and apply the "wpml_set_element_language_details" hook.

There seem to be many complicating factors like whether or not that post type has translations enabled in the WPML setting ahead of time; whether or not the translation is complete, or if the post or translation are drafts.

I'm wondering if there is a known way to migrate posts with their translations to a new post type.

If we disable WPML then switch all our posts to the new post type and then enable WPML how are we supposed to reconnect translations manually? Are we expected to have a spreadsheet with the Post IDs for the Original and Translations?

Anyway, this has been a very challenging thing to sort out and we could use assistance.

November 12, 2024 at 6:35 am #16390904

Dražen Duvnjak
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

I am afraid there is no official way from WPML or anything else we can recommend. This is more of a WP thing than WPML. As said, the WPML part is that you need to connect them as translation via hook suggested.

As advised before, you should first just migrate your posts from one CPT to another without WPML, then enable WPML and via our PHP hook adjust the posts language information and its translation of.

You can also do that manually as explained in the docs shared before, you will need to go edit the translated post, set the correct language for it, and then set that this is a translation of (correct default language post)

I am afraid there is no other way I can suggest, or am aware. From the WPML side, if you have issues with the hook or it is not working correctly, or you are not sure how to connect translation, we can try to help and advise, but note we can not write custom code or custom solutions for you, that is out of scope of our support. For that kind of work, you can hire a WPML Contractor: https://wpml.org/contractors/

Hope this helps.

Regards,
Drazen