【发布时间】:2023-01-14 01:39:08
【问题描述】:
我正在使用 get_post_meta,如下所示:
$job_owner = get_post_meta($post->ID, 'assignedUsers', true);
返回以下内容:
(
[total] => 1
[data] => Array
(
[0] => stdClass Object
(
[id] => 440968
[firstName] => John
[lastName] => Doe
[email] => john@website.com
)
)
)
我试图从对象中获取值,但每次我只是尝试使用 echo $job_owner 时都会遇到错误。错误是 -stdClass 类的对象无法转换为字符串
我尝试使用:
$array = json_decode(json_encode($job_owner), true);
返回数组:
Array
(
[total] => 1
[data] => Array
(
[0] => Array
(
[id] => 440968
[firstName] => Megan
[lastName] => Collins
[email] => megan@bridgeviewit.com
)
)
)
但我似乎无法使用echo $array[0]->id等获得任何回报......
我的理想方案是使用数组值作为变量在整个主题中使用。
【问题讨论】: