Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress json编码永久链接和图像_Php_Json_Wordpress - Fatal编程技术网

Php Wordpress json编码永久链接和图像

Php Wordpress json编码永久链接和图像,php,json,wordpress,Php,Json,Wordpress,我正在进行一个查询,用JSON编码一组wordpress post数据,如下所示: $query = new WP_Query( $args ); $posts = $query->get_posts(); foreach( $posts as $post ) { $output[] = array( 'id' => $post->ID, 'title' => $post->post_title, 'count' => $post-&g

我正在进行一个查询,用JSON编码一组wordpress post数据,如下所示:

$query = new WP_Query( $args ); 
$posts = $query->get_posts();   
foreach( $posts as $post ) {    
    $output[] = array( 'id' => $post->ID, 'title' => $post->post_title, 'count' => $post->custom_total_hits, 'soundcloud_url' => $post->soundcloud_song, 'soundcloud_id' => $post->soundcloud_ids);
}
echo json_encode($output);
但是,我如何将$post->ID的永久链接和附加图像的url添加到JSON中呢?为了得到类似于:

{
"id":28197,
"title":"Hazel English - More Like You",
"count":"000000421",
"soundcloud_url":"https:\/\/soundcloud.com\/hazelenglish\/hazel-english-more-like-you-2",
"soundcloud_id":"317317206",
"link":" ",
"image_url":" "
}
看这里:还有

正如您在文档中看到的,函数get_attached_media返回一个数组,其中包含从指定帖子中选择的所有类型的数据。

请看这里:和


正如您在文档中看到的,函数get_attached_media返回一个数组,其中包含从指定帖子中选择的所有类型的数据。

感谢您的帮助,如果我只想返回所附图像的url,该怎么办?因为我无法通过json访问url,因为密钥是附加媒体的ID(未知)。谢谢帮助,如果我只想返回附加图像的url怎么办?因为我无法通过json访问url,因为密钥是连接媒体的ID(未知)
$query = new WP_Query( $args ); 
$posts = $query->get_posts(); 
foreach( $posts as $post ) { 
$output[] = array( 
'id' => $post->ID, 
'title' => $post->post_title, 
'count' => $post->custom_total_hits, 
'soundcloud_url' => $post->soundcloud_song, 
'soundcloud_id' => $post->soundcloud_ids, 
'link' => get_permalink($post), 
'images' => get_attached_media('image', $post->ID) );
 } 
echo json_encode($output);