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 Waqas Bin Hasan 1 year, 8 months ago.

Assisted by: Waqas Bin Hasan.

Author Posts
September 2, 2023 at 10:27 pm #14330869

Bozv

Hi,

Basically, put this function in a translated site's theme's function.php

echo get_rest_url();

Now start browsing the wp-admin area by going to Posts tab for example.
Now, change the language from the top admin bar - hidden link

Confirm the Rest URL that is being printed on the screen due to the function is correct by putting it in another tab of your browser such as - hidden link or hidden link and so on..

Now, Change the language to All Languages and you will get rest URL like hidden link -- which is invalid ( 404 )!

Let me know how we can solve this temporarily also if possible. What would be the all URL for getting rest data for all content ?

September 4, 2023 at 10:05 am #14335299

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Bozv,

Thank you for contacting the support.

The "/all/" is a non-existent URL for /wp-json/. By default when you switch to "All Languages" the URL remains the same as of the default language. Means it returns content in the default language.

I've tried by echoing that get_rest_url() method in my 2021 theme's functions.php file and you can see the attached images for a reference.

In my sandbox site, English is the default language and All Languages also returns the same URL as of the default.

I am not sure how you are getting that URL, are you developing custom solutions involving custom programming? Can you please explain little more?

Regards.

rest-fi.png
rest-en.png
rest-el.png
rest-all.png
September 4, 2023 at 11:22 am #14336093

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Additionally I discussed with the team and they mention the following:

When making a GET request, the parameter lang=all (wp-json/wp/v2/pages/?lang=all) is not working for pages. We only support it for products

To make the ?lang=all parameter available, we can use this snippet:

add_filter( 'rest_page_query', function( $args, $request ) {
if ( 'all' === $request->get_param('lang') ) {
$args['suppress_filters'] = true;
}
return $args;
}, 10, 2 );

Please let me know if that helps.

September 8, 2023 at 10:11 pm #14368655

Bozv

Maybe it has to do something regarding setting language for all content by default. I will further test on a new env. and update later. Thanks.

September 11, 2023 at 5:48 am #14372731

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Sure, please take your time.