Summery Summery

Retrieves media attached to the passed post.

Syntax Syntax

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

Parameters Parameters


(Required) Mime type.


(Optional) Post ID or WP_Post object. Default is global $post.

Return Return

(WP_Post[]) Array of media attached to the given post.

Source Source

File: wp-includes/media.php

	 * was the default behavior prior to version 4.8.0, but this query is
	 * expensive for large media libraries.
	 * @since 4.7.4
	 * @since 4.8.0 The filter's default value is `true` rather than `null`.
	 * @link
	 * @param bool|null $show Whether to show the button, or `null` to decide based
	 *                        on whether any video files exist in the media library.
	$show_video_playlist = apply_filters( 'media_library_show_video_playlist', true );
	if ( null === $show_video_playlist ) {
		$show_video_playlist = $wpdb->get_var(
			FROM $wpdb->posts
			WHERE post_type = 'attachment'
			AND post_mime_type LIKE 'video%'
			LIMIT 1

	 * Allows overriding the list of months displayed in the media library.
	 * By default (if this filter does not return an array), a query will be
	 * run to determine the months that have media items.  This query can be
	 * expensive for large media libraries, so it may be desirable for sites to
	 * override this behavior.
	 * @since 4.7.4
	 * @link
	 * @param array|null $months An array of objects with `month` and `year`
	 *                           properties, or `null` (or any other non-array value)
	 *                           for default behavior.


Changelog Changelog

Version Description
3.6.0 Introduced.


Leave a Reply