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.

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

This topic contains 4 replies, has 2 voices.

Last updated by Lauren 4 years, 6 months ago.

Assisted by: Lauren.

Author Posts
April 17, 2020 at 1:24 am #5927805

nicolasT-34

Tell us what you are trying to do?

I am building a Gatsby based WordPress site and I am looking for an endpoint to retrieve all translated taxonomy term at once.

Is there any documentation that you are following?

Yes my work is based on this tutorial hidden link
And it's inspired by https://wpml.org/forums/topic/how-can-i-get-all-pages-original-and-translated-in-the-api-response/#post-3072937

It described how to modify WP to retrieve all translated content from custom post in the REST API and it works fine thanks to this code :
add_action('rest_api_init', function () {
if (defined('REST_REQUEST') && REST_REQUEST) {
// Add all WPML language translations to rest api when type is page
add_action('parse_query', function ($q) {
if (in_array($q->query_vars['post_type'], array('page', 'post', 'millesimes'))) {
$q->query_vars['suppress_filters'] = true;
}
});
}
});

You can see that this end point will get all translated content (we added the wpml_current_locale variable using wpml-rest-api plugin) :
hidden link

However we would like to know how to do the same for taxonomies so this endpoint hidden link will display all EN & FR content in the same endpoint.
French content can be see here hidden link

Thank you very much

April 19, 2020 at 3:14 pm #5942975

Lauren
Supporter

Languages: English (English )

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

Hi there, thanks for contacting WPML. Can you please share the code you are currently using to display the taxonomies? For example: https://developer.wordpress.org/reference/functions/get_terms/

Per our support policy, I am not able to provide a custom code solution but I will be happy to review your existing code to see if anything stands out. I found a similar ticket here, although the issue is the opposite of yours, and this client was trying to filter by language: https://wpml.org/forums/topic/rest-api-get_terms-in-rest-api-function-returns-wrong-language/#post-3514003

Without the language parameter, it should display all languages. Please check and see if your taxonomies are set to translatable or translatable or fallback to default.

April 19, 2020 at 3:46 pm #5943037

Lauren
Supporter

Languages: English (English )

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

Actually, I just tested this link in a cleared browser and now I see both English and French hidden link

For example
wpml_current_locale: "en_US",
wpml_translations: [
{
locale: "fr_FR",
id: 287,
post_title: "Pastourelle de Clerc Milon",
href: "hidden link"
}
],

April 22, 2020 at 8:23 pm #5971983

nicolasT-34

Hi Lauren,
Thanks for your feedback, the taxonomies where displayed automatically by WP REST API, so there was no custom code beside this custom code in our functions.php but this code was only targetting posts and not taxonomies hence my question around how to display all taxonomies from all languages in one REST endpoint.

Right now we rebuild the site using posts instead of taxonomies but if you have some tips about how to make WPML show terms from all languages in REST, I would appreciate it.

Thanks a lot

April 22, 2020 at 10:30 pm #5972319

Lauren
Supporter

Languages: English (English )

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

Okay so it sounds like everything is working as expected with the way you currently have it set up - is that correct?

As for the taxonomies, currently there is no way to display the list of all terms in all languages, and it will require custom programming use the get_terms function. You can see an example here: https://wpml.org/forums/topic/rest-api-get_terms-in-rest-api-function-returns-wrong-language/

However, because it requires custom programming, I don't have a full solution for you. If you need further assistance with custom programming, I would suggest contacting one of our certified partners from this link: http://wpml.org/documentation/support/wpml-contractors/