Retrieve media attached to the passed post.

Signature

get_attached_media( $type, $post = 0 )
type
 (string) Mime type.
post
 (int|WP_Post) Optional. Post ID or WP_Post object. Default is global $post.
Default: 0

Return

(array) Found attachments.

Source

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',
	);

	/**
	 * Filter 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.
17 more lines...
WP Trac GitHub

Link here