get_attached_media()
get_attached_media( string $type, int|WP_Post $post )
检索附加到传递的邮件的媒体。
Retrieves media attached to the passed post.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$type | (string) | 必需 | Mime类型。 |
$post | (int | WP_Post) | 可选 | Post ID或WP_Post对象。默认值为全局$post。 |
返回(Return)
(WP_Post[])附加到给定Post的媒体数组。
源码(Source)
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
3.6.0 | wp-includes/media.php:4066 | 2 | 5 |
笔记(Notes)
通过传递空字符串,可以获取所有附加的媒体,无论其类型如何:
需要注意的是,这个函数只返回第一次上传/添加到帖子中的附件。
实例
get_attached_media() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_attached_media-2/