get_attached_media()
最后更新于:2021-11-26 04:27:20
get_attached_media( string$type, int|GC_Post$post)Retrieves media attached to the passed post.
参数
- $type
-
(string) (Required) Mime type.
- $post
-
(int|GC_Post) (Optional) Post ID or GC_Post object. Default is global $post.
响应
(GC_Post[]) Array of media attached to the given post.
源文件
文件: gc-includes/media.php
function get_attached_media( $type, $post = 0 ) {
$post = get_post( $post );
if ( ! $post ) {
return array();
}
$args = array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => $type,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
);
/**
* Filters arguments used to retrieve media attached to the given post.
*
* @since 3.6.0
*
* @param array $args Post query arguments.
* @param string $type Mime type of the desired media.
* @param GC_Post $post Post object.
*/
$args = apply_filters( 'get_attached_media_args', $args, $type, $post );
$children = get_children( $args );
/**
* Filters the list of media attached to the given post.
*
* @since 3.6.0
*
* @param GC_Post[] $children Array of media attached to the given post.
* @param string $type Mime type of the media desired.
* @param GC_Post $post Post object.
*/
return (array) apply_filters( 'get_attached_media', $children, $type, $post );
}