I'm making an Ionic app that accesses a Wordpress site using the WP REST API V2 plugin. Given this code in my controller:
$http.get('http://www.greenfundsuriname.org/wp-json/wp/v2/posts/3701').then(function(response) {
$log.log(response);
});
$http.get('http://www.greenfundsuriname.org/wp-json/wp/v2/posts/').then(function(response) {
$log.log(response);
});
I get two perfectly fine responses on my local machine and in the iOS simulator, see:
On my actual device, the single post works fine but the posts URL gives me an empty array as the data response:
How is this possible?
Turns out one of the headers in the request caused this. Since my OS language is set to Dutch the Accept-Language header asked for Dutch posts in the Wordpress. Wordpress correctly returned an empty array. Other people – whose OS is set to English – get all the English Wordpress posts. Solved it like this:
$http.get( url, {
headers: {'Accept-Language': 'en-US,en;q=0.8,nl;q=0.6'}
});