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.

Our next available supporter will start replying to tickets in about 11.33 hours from now. Thank you for your understanding.

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Christopher 2 weeks, 1 day ago.

Assigned support staff: Lauren.

Author Posts
September 19, 2019 at 12:32 pm #4604699

Christopher

Hey

We are trying to use REST API to add translations to articles (and we cant). For now, we just can add posts in the default language set in wpml.

We want to know:
- how WPML is integrated with REST API?
- how to add new post using REST API, to a different language version (not default)
- how to add many translations at once, using REST API?

September 19, 2019 at 2:54 pm #4606631

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Thank you for contacting WPML support. I'll be happy to help you with this.

Make sure you are using the latest version of WPML and that you are using the same URL format to access the API. For example:

If you are using URL format as directories: - site.com/en/wp-json/wp/v2/posts?per_page=3&status=publish&_embed

If you are using URL with parameter format: - site.com/wp-json/wp/v2/posts?per_page=3&status=publish&_embed&lang=en

To see the current URL format for your site, click on the WPML > Languages > Language URL format.

Please let me know if you need any further assistance and I will be happy to help.

September 21, 2019 at 1:05 pm #4615979

Christopher

Thank you for the answer, but I think we don't understand each other.

My task is to add a new post in a different language versions, not to download the list of posts in a given language.

Maybe you have an example of adding an post in given languages via REST API?

September 24, 2019 at 4:10 pm #4632991

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Thanks for clarifying. Unfortunately, there is not an easy solution available yet, this will require custom code. Currently, there is not a way to publish a new post to a secondary language using WPML and REST API. Some clients have found a workaround by publishing to the default language and then automatically duplicating the post using WPML API hooks. You can reference this ticket as an example: https://wpml.org/forums/topic/using-wp-rest-api-to-create-posts-with-wpml-integration/

October 3, 2019 at 9:42 pm #4691557

Christopher

Hey, we have made some progress,

Now we are able to add further posts in the language versions by providing the language code in the endpoint address:
hidden link
hidden link

Posts are added in the correct language, but unfortunately, they are separate posts. The problem now is to posts and translations, just like they are linked in wp admin panel.

At the moment, it adds the first as the main one in the default language, and passes the ID thus obtained for the language versions in META. Pass by parameter: icl_lang_duplicate_of (idea found at: https://wpml.org/forums/topic/use-rest-api-to-create-post-in-different-languages/) which has the ID value from the main post.

Unfortunately, this does not associate the posts with each other. They continue to add in their own languages, but are not related to each other.

What to do to tie them together? What parameters to use?