检索附加到已传递帖子的媒体。

原型

get_attached_media( string $type, int|WP_Post $post )

参数

$type (string) (Required) 哑剧型。

$post (int|WP_Post) (Optional)  发布ID或WP_Post对象。默认为全球$ post。

返回值

(array)  找到附件。

源文件

路径:wp-includes/media.php

<?php
...
function get_attached_media( $type, $post = 0 ) {
	if ( ! $post = get_post( $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 mixed  $post Post ID or 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 array  $children Associative array of media attached to the given post.
	 * @param string $type     Mime type of the media desired.
	 * @param mixed  $post     Post ID or object.
	 */
	return (array) apply_filters( 'get_attached_media', $children, $type, $post );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/get_attached_media/