Hi,
I'm trying to develop a site using GatsbyJs and WordPress as headless cms.
I used this code in order to get all posts and pages in all available languages:
add_action('rest_api_init', function () {
if (defined('REST_REQUEST') && REST_REQUEST) {
add_action('parse_query', function( $q ) {
$q->query_vars['suppress_filters'] = true;
});
}
});
Is there any way get all media (the same done for posts with the code above)?
Url "/wp-json/wp/v2/media" display only default language medias..
Can you tell me if you tried to get the media in all the other languages by adding the language part in the URL like /fr/wp-json/wp/v2/media , for example? This link should work if you selected the Different languages in directories option in Dashboard → WPML → Languages → Language URL format. Can you try this and tell me if it's helping you retrieve the media in a secondary language?
I looked over this a bit more and I could see that the WPML REST API is not made to return all the media elements under just one call. There's one small piece of code that might alter the query result. This is it:
add_action('rest_api_init', function () {
if (defined('REST_REQUEST') && REST_REQUEST) {
add_action('parse_query', function( $q ) {
$q->query_vars['suppress_filters'] = true;
});
}
});
You can give it a try and see if there's any difference.
Sorry for my mistake. I forgot that you mentioned that piece of code already, in your first message.
I looked a bit more on this but I'm afraid that, at least for now, you can get the media files only like I mentioned, by accessing the route for each language.
You can suggest this as a feature request right here https://wpml.org/suggest-a-new-feature-for-wpml/. This way, my colleagues will have a look and see what can be done about it, in a future update.
Thanks,
Radu
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.