Skip Navigation

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 4 replies, has 2 voices.

Last updated by Raja Mohammed 1 month ago.

Assigned support staff: Raja Mohammed.

Author Posts
January 20, 2021 at 7:22 pm #7891337

eliaL

Non ho trovato molte informazioni riguardo le rest api.
Sarebbe comodo avere una sezione nella doc, se non esiste di già.

Apperte questo, avrei bisogno di sapere se è possibile ottenere le traduzioni di un post tramite lo slug.

Ad esempio:
Ottengo un post tramite slug in lingua italiana: /it/wp-json/wp/v2/posts?slug=ciao-mondo
Da questo post avrei poi bisogno di ottenere anche gli slug dello stesso post in altre lingue.

January 20, 2021 at 10:31 pm #7892195

eliaL

I have not found many resources about rest API, it would be useful to have description about all the parameters and fields added by the plugin.

Anyway, I would like to know if it's possible to get a post translations by slug.

Example
I get a post by slug in italian:
it/wp-json/wp/v2/posts?slug=ciao-mondo
Then I need a way to find the english version of it:
en/wp-json/wp/v2/posts?slug=ciao-mondo (not working because slug need to be translated)

January 21, 2021 at 9:56 am #7894991

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello there,

Please try adding this piece of code to functions.php file let me know if that helps

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

Regards
Raja

January 21, 2021 at 5:06 pm #7899633

eliaL

I added it, but I don't have the expected results, seems like its returning every post in every language, this is not what I was asking for.
I need a way to relate a translated post (say an italian post) to its other translations (in english for example).
This would be useful, as it will let me put a link to other translations of the same post, and also add hreflang meta tags for seo.

January 22, 2021 at 6:54 am #7903449

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Oops, I misread the request,

Currently, there is no way to get translated posts using the original post ID.There is a third party plugin hidden link that enable the wpml_current_locale and wpml_translations in the REST response.

However, this seems to be a missing feature and I would kindly request you please submit this form as part of the feature request process https://wpml.org/suggest-a-new-feature-for-wpml/

Regards
Raja