Search code examples
phpjsonwordpresswp-api

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 source json can be found here.

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!


Solution

  • 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