WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get attached media

Description

Retrieve media attached to the passed post. Uses get_children().

Usage

 <?php get_attached_media$type$post_id ?> 

Parameters

$type
(string) (required) (Mime) type of media desired.
Default: None
$post_id
(integer) (optional) Post ID, by default the current post ID.
Default: 0

Return

(array) 
WP_Post objects of found attachments.

Examples

Get image attachment(s) to the current Post:

$media = get_attached_media( 'image' );

Get attachment(s) of mime-type 'audio' to the Post with an ID of 102:

$media = get_attached_media( 'audio', 102 );

Change Log

Source File

get_attached_media() is located in wp-includes/media.php.

Related

Audio: wp_audio_shortcode(), wp_get_audio_extensions(), get_attached_media(), wp_embed_handler_audio(), wp_mediaelement_fallback(), wp_read_audio_metadata(), wp_add_id3_tag_data()

Video: wp_video_shortcode(), wp_get_video_extensions(), get_attached_media(), wp_embed_handler_video(), wp_mediaelement_fallback(), wp_read_video_metadata(), wp_add_id3_tag_data()

See also index of Function Reference and index of Template Tags.