You are trying to access an object inside an array. To retrieve the data from term_id
, you can use:
$value[0]['tax'][0]->term_id
Notice that the first 3 steps are arrays, and then there is a WP_Object
, which has an array inside.
Breaking Down the Code
$value - returns the entire array
$value[0] - returns the first element of the array
$value[0]['tax'] - returns the `tax` element and all of its contents
$value[0]['tax'][0] - returns the first element of `tax`
$value[0]['tax'][0]->term_id - points to the term id inside the above
UPDATE
You don’t need to use json_encode
or json_decode
. Simply use a foreach to output the content:
foreach( $results as $key => $value) {
echo $value['tax']->term_id;
}
You might also want to use $value['tax'][0]->term_id
if there are multiple terms inside the tax.