I’m using AngularJS with the WordPress Rest API. I am making a get request which returns an object. To get a featured image I have to use the ‘?embed’ parameter which gives be another object called _embedded.
The problem is the object I want that is inside _embedded is called wp:featuredmedia. If I reference it like this in angular I get a syntax error.
Here is my code
$http.get(queries[0], {'cache': true}).
then(function(response) {
$scope.careers_title = strip(response.data.title.rendered);
$scope.careers_content = strip(response.data.content.rendered);
$scope.careers_feature_image = strip(response.data.featured_media);
console.log(response.data._embedded);
});
The console.log returns this
Object {author: Array[1], wp:featuredmedia: Array[1], wp:term: Array[2]}author: Array[1]wp:featuredmedia: Array[1]0: Object_links: Objectalt_text: ""author: 1date: "2016-04-25T09:33:52"id: 46link: "http://localhost:8888/rubis/wordpress/energy-efficiency/tp-roundall/"media_details: Objectmedia_type: "image"mime_type: "image/png"slug: "tp-roundall"source_url: "http://localhost:8888/rubis/wordpress/wp-content/uploads/2016/04/tp-roundall.png"title: Objecttype: "attachment"__proto__: Objectlength: 1__proto__: Array[0]wp:term: Array[2]__proto__: Object
Indeed you cannot write:
This is a forbidden property name. However any string is accepted so you can access it this way:
hello in addition the previous example if you
use google inspect you can just look at the json response and copy jsonson path
data._embedded[“wp:featuredmedia”][“0”].media_details.sizes.medium