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 1 reply, has 2 voices.

Last updated by Bobby 5 months, 1 week ago.

Assigned support staff: Bobby.

Author Posts
May 9, 2019 at 7:13 pm #3779057

jaredD-2

Hello,

I'm developing a headless multilingual site using the WordPress REST API to access Posts. I'd like to link from one post to it's translated version.

For instance, if requesting
hidden link

Is it possible to retrieve a link, slug or ID of it's translated version in the JSON response?

I believe my issue is similar to the one discussed here:
https://wpml.org/forums/topic/how-to-get-translated-post-via-origin-post-id-through-rest/

although I do not see the "wpml_current_locale" or "wpml_translations" referenced in Marcel's response.

Thank you!

May 10, 2019 at 6:59 pm #3787483

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi There,

after running some tests and consulting with our developers it seems that this is not an expected result that is shown in the ticket here

https://wpml.org/forums/topic/how-to-get-translated-post-via-origin-post-id-through-rest/

The user has used some custom coding to get a specific result back from the wp-rest api

you can do this with custom code , here are some documentations that can help

https://developer.wordpress.org/rest-api/
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

additionally please review the following function another user shared in an older post

if you add it within your theme's functions.php it will enable to show the translates page as well with the original pages all in one page when just calling /posts/

add_action('rest_api_init', function () {
if (defined('REST_REQUEST') && REST_REQUEST) {
add_action('parse_query', function( $q ) {
$q->query_vars['suppress_filters'] = true;
});
}
});

unfortunately as this is custom coding we cannot provide further support within the forum but do recommend contacting our 3rd party contractors

The topic ‘[Closed] Slug or ID of translated post via REST API’ is closed to new replies.