Chris Townsend Chris Townsend - 2 years ago 79
PHP Question

How to reference an object that has a semi colon in

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(;
$scope.careers_content = strip(;
$scope.careers_feature_image = strip(;

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

Answer Source

Indeed you cannot write:

This is a forbidden property name. However any string is accepted so you can access it this way:['wp:featuredmedia']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download