Skip Navigation

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

Problem:
The client is using a headless WordPress setup and is encountering issues when trying to access translated content via the REST API. The translated content is only returned when the client is logged in as an administrator; otherwise, the default language content is served.
Solution:
1. We recommended the client to ensure that all translated pages are fully translated and published.
2. We advised checking if the second language is hidden in the WPML settings under WPML > Languages.
3. The correct approach to access translated content via the REST API is to include the language code before the REST API path. For example:

https://shiny-ukulele.sandbox.otgs.work/es/wp-json/wp/v2/pages?slug=tienda

If these steps do not resolve the issue, or if the solution seems outdated or irrelevant to your case, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket.

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 3 replies, has 0 voices.

Last updated by Dražen 2 months, 3 weeks ago.

Assisted by: Dražen.

Author Posts
November 27, 2024 at 8:27 pm #16451616

tinaM-8

Background of the issue:
I have a headless WordPress setup and I am pulling page content via the REST API. I can load the default language content fine, but when I request translated content, it just returns the default language. For example, if I access: /wp-json/wp/v2/pages?slug=about-us&lang=en_CA I get the default language's content, not my translated content. However, if I am logged into WordPress and I access the URL, I do get the translated content.

Symptoms:
Translated content is not served through the REST API unless logged in as an administrator.

Questions:
Is there a way to allow the translated content to be served without being logged in as an administrator through the API?

November 28, 2024 at 8:06 am #16453259

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

thanks for contacting us.

If it works when logged in, it should also work when not logged in, I just tested it.

1) Can you please check your translated pages are translated 100% and published?

2) Can you please check if you have not set to hide the 2nd language from WPML > Languages?

Regards,
Drazen

Slika zaslona 2024-11-28 u 09.04.30.png
November 28, 2024 at 2:21 pm #16455697

tinaM-8

My pages are translated. I have the about-us page, for the "en" language (default) it is ID 12, for my translation "en_CA" the ID is 51.

If I access /wp-json/wp/v2/pages?slug=about-us&lang=en_CA from the browser I am logged into wordpress as I get page with ID 51.

If I access /wp-json/wp/v2/pages?slug=about-us&lang=en_CA while I am not logged in I get a page with ID 12.

The language is not set to hidden. Every thing is published and translated.

November 29, 2024 at 7:51 am #16457983

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

thanks for getting back.

I checked further, you need to language code before the REST API path, so not at the end, but for example like this:

<em><u>hidden link</u></em> 

and then it works fine.

Please check.

Regards,
Drazen