Aaron Aaron - 2 months ago 11
JSON Question

Display json array

I am trying to read an api i have implemented with Wordpress using WP-API V2, i have used several plugins to return the information i need...

The json can be found here:
http://dev.selectparkhomes.com/wp-json/wp/v2/property?filter[taxonomy]=property-city&filter[term]=fell-view-park

I need to return pure_taxonomies->property-status->name

I have tried the following but i just get a blank page:

foreach($select_api as $p)
{
echo '
Status:'.$p->pure_taxonomies->property-status->name.'
';
}


Any help would be great!

Answer

First of all, if you have json_encoded string, you should decode it with json_decode() I decoded your json and get array with two elements. Your error is probably because of hyphen property-status in name of property. You should use curly braces:

Status:'.$p->pure_taxonomies->{"property-status"}[0]->name.'

IMPORTANT.

  1. Use curly braces for property names with hyphen

  2. Don't forget that in your structure property-status is array. That's why I used index 0 to get first element

Comments