get_attached_media

The timeline below displays how wordpress function get_attached_media has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.4

/**
 * Retrieves media attached to the passed post.
 *
 * @since 3.6.0
 *
 * @param string      $type Mime type.
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return WP_Post[] Array of media attached to the given post.
 */
function get_attached_media($type, $post = 0)
{
    $post = get_post($post);
    if (!$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 WP_Post $post Post 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 WP_Post[] $children Array of media attached to the given post.
     * @param string    $type     Mime type of the media desired.
     * @param WP_Post   $post     Post object.
     */
    return (array) apply_filters('get_attached_media', $children, $type, $post);
}

WordPress Version: 5.3

/**
 * Retrieves media attached to the passed post.
 *
 * @since 3.6.0
 *
 * @param string      $type Mime type.
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return array Found attachments.
 */
function get_attached_media($type, $post = 0)
{
    $post = get_post($post);
    if (!$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);
}

WordPress Version: 4.6

/**
 * Retrieves media attached to the passed post.
 *
 * @since 3.6.0
 *
 * @param string      $type Mime type.
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return array Found attachments.
 */
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);
}

WordPress Version: 4.2

/**
 * Retrieves media attached to the passed post.
 *
 * @since 3.6.0
 *
 * @param string      $type Mime type.
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return array Found attachments.
 */
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.
     * @param mixed  $post Post ID or object.
     */
    $args = apply_filters('get_attached_media_args', $args, $type, $post);
    $children = get_children($args);
    /**
     * Filter 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);
}

WordPress Version: 4.0

/**
 * Retrieve media attached to the passed post.
 *
 * @since 3.6.0
 *
 * @param string      $type Mime type.
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return array Found attachments.
 */
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.
     * @param mixed  $post Post ID or object.
     */
    $args = apply_filters('get_attached_media_args', $args, $type, $post);
    $children = get_children($args);
    /**
     * Filter 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);
}

WordPress Version: 3.9

/**
 * Retrieve media attached to the passed post.
 *
 * @since 3.6.0
 *
 * @param string $type (Mime) type of media desired
 * @param mixed $post Post ID or object
 * @return array Found attachments
 */
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.
     * @param mixed  $post Post ID or object.
     */
    $args = apply_filters('get_attached_media_args', $args, $type, $post);
    $children = get_children($args);
    /**
     * Filter the
     *
     * @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);
}

WordPress Version: 3.7

/**
 * Retrieve media attached to the passed post
 *
 * @since 3.6.0
 *
 * @param string $type (Mime) type of media desired
 * @param mixed $post Post ID or object
 * @return array Found attachments
 */
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');
    $args = apply_filters('get_attached_media_args', $args, $type, $post);
    $children = get_children($args);
    return (array) apply_filters('get_attached_media', $children, $type, $post);
}