WordPress.org

Ready to get started?Download WordPress

Codex

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

Function Reference/get attached media

Contents

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) 
Class_Reference/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_audio(), get_attached_media(), get_embedded_audio(), get_embedded_media(), wp_embed_handler_audio(), wp_mediaelement_fallback(), wp_read_audio_metadata(), wp_add_id3_tag_data(), the_post_format_audio(), get_the_post_format_media(), get_content_audio(), get_content_media()

Video: wp_video_shortcode(), wp_get_video_extensions(), get_attached_video(), get_attached_media(), get_embedded_video(), get_embedded_media(), wp_embed_handler_video(), wp_mediaelement_fallback(), wp_read_video_metadata(), wp_add_id3_tag_data(), the_post_format_video(), get_the_post_format_media(), get_content_video(), get_content_media()

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