Skip Navigation

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

Problem:
I would like to use Rest API with WPML to manage posts / pages
Solution:
Creating post and page translation using Rest API is not tightly integrated with WPML yet, You can use language parameter to create translation (?lang=fr) however it will still need some custom work to connect the translation with the original content of the post / page.

There is a workaround but you need to implement it . A wpml user shared this before sometime ago, other users reported that is working great, but have in mind that this is not coming from WPML so we cannot support it:

---------------

Finally i created a custom endpoint to link the 2 translations.

This is my code : https://gist.github.com/djoo/5518bcf4ccef93ab83d91787c41e929a

So the process is :
1- create the first post in language 1 (classic API POST call)
2- create the second post in language 2 (classic API POST call)
3- link both (custom endpoint)

Hope is gonna help people

---------------

You can use our hooks to add a few more functionalities: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

NOTE: While this is a great workaround always have a backup in place when using custom code either provided by us or another member of this forum.

0% of people find this useful.

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.

This topic contains 3 replies, has 2 voices.

Last updated by Andreas 2 years, 9 months ago.

Assisted by: Andreas.

Author Posts
August 16, 2022 at 1:30 pm #11873083

futureG

I am building an app that will connect to my WordPress app via REST APIs.
It is needed to manage posts and their translations via REST APIs. But I cannot find helpful documentation for this.

Is there any way to fetch post translations, link translations to post, ..etc via REST APIs?

I only found this https://wpml.org/documentation/support/rest-api-dependencies

Site URL: hidden link

August 16, 2022 at 2:50 pm #11873803

Andreas

Hello there

Thank you for contacting us. I am happy to help you.

If you wish to use REST APi with WooCommerce we are having well documented: https://wpml.org/documentation/related-projects/woocommerce-multilingual/using-wordpress-rest-api-woocommerce-multilingual/

If you wish to use the Posts/Pages for adding translation I am afraid, Creating post and page translation using Rest API is not tightly integrated with WPML yet, You can use language parameter to create translation (?lang=fr) however it will still need some custom work to connect the translation with the original content of the post / page.

There is a workaround but you need to implement it . A wpml user shared this before sometime ago, other users reported that is working great, but have in mind that this is not coming from WPML so we cannot support it:

---------------

Finally i created a custom endpoint to link the 2 translations.

This is my code : hidden link

So the process is :
1- create the first post in language 1 (classic API POST call)
2- create the second post in language 2 (classic API POST call)
3- link both (custom endpoint)

Hope is gonna help people

---------------

NOTE: While this is a great workaround always have a backup in place when using custom code either provided by us or another member of this forum.

August 16, 2022 at 3:30 pm #11873991

futureG

Thank you so much Andereas for your reply!

I am not using WooCommerce, just normal posts/pages.

Unfortunately, I am building an app that should be ready to communicate with any WordPress app that uses normal WPML. So it will not be a solution for me to do any type of customization on the WordPress app side.

August 17, 2022 at 8:07 am #11878075

Andreas

If you are building an app, you can include the above code as compatibility ( of course you need to add a few things more and cover at least the default Post Types ) and you can make it work out of the box.

You can use our hooks to add a few more functionalities: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

Also you can propose to add this functionality using this form : https://wpml.org/suggest-a-new-feature-for-wpml/

When we released Rest API support you can either remove your compatibility code or keep it, since WPML Hooks will be the same.

I hope this helps. Please let us know how it goes or if you need any further assistance. I'll gladly help you. 🙂

Regards,
Andreas