我按照以下方式通过 REST API 检索帖子:$response = wp_remote_get(get_home_url()."2/wp-json/wp/v2/posts?include=".$postId);$data = json_decode($response['body'], true);然后我有:'acf' => array ( 'descrizione_lavoro' => ' Lorem ipsum dolor ', 'location' => array ( 'lat' => '41.36256133817761', 'lng' => '2.131976960327165', ), 'categories' => array ( 0 => 627, ), 'partner' => array ( 0 => 'Sandra Yannis', ), 'collaboratori' => array ( 0 => 'Fran White', 1 => 'Sam Jumper', ), 'importo' => '1200000', 'galleria' => array ( 0 => array ( 'ID' => 128345, 'id' => 128345, 'title' => 'villa1', 'filename' => 'villa1.jpg', 'filesize' => 78350, 'url' => 'http://example.com/ing2/wp-content/uploads/2019/03/villa1.jpg',我需要得到url所以我这样做:var_dump($data[0]['acf']["galleria"][0]['url']);并且工作正常,但galleria如果我这样做,我有多个索引:var_dump($data[0]['acf']["galleria"][1]['url']);我将获得第二张图像,但可能有很多图像,我将如何循环以检索所有图像?
1 回答
茅侃侃
TA贡献1842条经验 获得超21个赞
用
foreach( $data[0]['acf']["galleria"] as $gallery ) {
echo $gallery['url'];
}
- 1 回答
- 0 关注
- 142 浏览
添加回答
举报
0/150
提交
取消