I'm trying to call a post from a Wordpress install using WP REST API. I keep getting an error in return and I can't find out why. Do I need to authenticate? One website said I don't need to authenticate for a GET request. WP REST API: Version 2.0-beta9. Here is the code I am using:
$(document).ready(function () {
setTimeout(GetPosts, 2000);
function GetPosts() {
$.ajax({
url: '',
data: {
filter: {
'posts_per_page': 1
}
},
dataType: 'json',
type: 'GET',
success: function(data) {
console.log(data);
},
error: function() {
console.log('error');
}
});
}
})
I'm trying to call a post from a Wordpress install using WP REST API. I keep getting an error in return and I can't find out why. Do I need to authenticate? One website said I don't need to authenticate for a GET request. WP REST API: Version 2.0-beta9. Here is the code I am using:
$(document).ready(function () {
setTimeout(GetPosts, 2000);
function GetPosts() {
$.ajax({
url: 'http://easterly.haamap/wp-json/posts',
data: {
filter: {
'posts_per_page': 1
}
},
dataType: 'json',
type: 'GET',
success: function(data) {
console.log(data);
},
error: function() {
console.log('error');
}
});
}
})
What version of the REST API are you using? If you're using the version that's bundled with WordPress 4.4 (ie, v2), you'll need to change your url
to something like http://example/wp-json/wp/v2/posts
.
WP API version 2 docs