get_media_items

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

WordPress Version: 6.1

/**
 * Retrieves HTML for media items of post gallery.
 *
 * The HTML markup retrieved will be created for the progress of SWF Upload
 * component. Will also create link for showing and hiding the form to modify
 * the image attachment.
 *
 * @since 2.5.0
 *
 * @global WP_Query $wp_the_query WordPress Query object.
 *
 * @param int   $post_id Post ID.
 * @param array $errors  Errors for attachment, if any.
 * @return string HTML content for media items of post gallery.
 */
function get_media_items($post_id, $errors)
{
    $attachments = array();
    if ($post_id) {
        $post = get_post($post_id);
        if ($post && 'attachment' === $post->post_type) {
            $attachments = array($post->ID => $post);
        } else {
            $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC'));
        }
    } else if (is_array($GLOBALS['wp_the_query']->posts)) {
        foreach ($GLOBALS['wp_the_query']->posts as $attachment) {
            $attachments[$attachment->ID] = $attachment;
        }
    }
    $output = '';
    foreach ((array) $attachments as $id => $attachment) {
        if ('trash' === $attachment->post_status) {
            continue;
        }
        $item = get_media_item($id, array('errors' => isset($errors[$id]) ? $errors[$id] : null));
        if ($item) {
            $output .= "\n<div id='media-item-{$id}' class='media-item child-of-{$attachment->post_parent} preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-{$id}' class='hidden'></div><div class='filename hidden'></div>{$item}\n</div>";
        }
    }
    return $output;
}

WordPress Version: 5.9

/**
 * Retrieve HTML for media items of post gallery.
 *
 * The HTML markup retrieved will be created for the progress of SWF Upload
 * component. Will also create link for showing and hiding the form to modify
 * the image attachment.
 *
 * @since 2.5.0
 *
 * @global WP_Query $wp_the_query WordPress Query object.
 *
 * @param int   $post_id Post ID.
 * @param array $errors  Errors for attachment, if any.
 * @return string
 */
function get_media_items($post_id, $errors)
{
    $attachments = array();
    if ($post_id) {
        $post = get_post($post_id);
        if ($post && 'attachment' === $post->post_type) {
            $attachments = array($post->ID => $post);
        } else {
            $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC'));
        }
    } else if (is_array($GLOBALS['wp_the_query']->posts)) {
        foreach ($GLOBALS['wp_the_query']->posts as $attachment) {
            $attachments[$attachment->ID] = $attachment;
        }
    }
    $output = '';
    foreach ((array) $attachments as $id => $attachment) {
        if ('trash' === $attachment->post_status) {
            continue;
        }
        $item = get_media_item($id, array('errors' => isset($errors[$id]) ? $errors[$id] : null));
        if ($item) {
            $output .= "\n<div id='media-item-{$id}' class='media-item child-of-{$attachment->post_parent} preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-{$id}' class='hidden'></div><div class='filename hidden'></div>{$item}\n</div>";
        }
    }
    return $output;
}

WordPress Version: 5.5

/**
 * Retrieve HTML for media items of post gallery.
 *
 * The HTML markup retrieved will be created for the progress of SWF Upload
 * component. Will also create link for showing and hiding the form to modify
 * the image attachment.
 *
 * @since 2.5.0
 *
 * @global WP_Query $wp_the_query WordPress Query object.
 *
 * @param int   $post_id Optional. Post ID.
 * @param array $errors  Errors for attachment, if any.
 * @return string
 */
function get_media_items($post_id, $errors)
{
    $attachments = array();
    if ($post_id) {
        $post = get_post($post_id);
        if ($post && 'attachment' === $post->post_type) {
            $attachments = array($post->ID => $post);
        } else {
            $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC'));
        }
    } else if (is_array($GLOBALS['wp_the_query']->posts)) {
        foreach ($GLOBALS['wp_the_query']->posts as $attachment) {
            $attachments[$attachment->ID] = $attachment;
        }
    }
    $output = '';
    foreach ((array) $attachments as $id => $attachment) {
        if ('trash' === $attachment->post_status) {
            continue;
        }
        $item = get_media_item($id, array('errors' => isset($errors[$id]) ? $errors[$id] : null));
        if ($item) {
            $output .= "\n<div id='media-item-{$id}' class='media-item child-of-{$attachment->post_parent} preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-{$id}' class='hidden'></div><div class='filename hidden'></div>{$item}\n</div>";
        }
    }
    return $output;
}

WordPress Version: 5.4

/**
 * Retrieve HTML for media items of post gallery.
 *
 * The HTML markup retrieved will be created for the progress of SWF Upload
 * component. Will also create link for showing and hiding the form to modify
 * the image attachment.
 *
 * @since 2.5.0
 *
 * @global WP_Query $wp_the_query WordPress Query object.
 *
 * @param int $post_id Optional. Post ID.
 * @param array $errors Errors for attachment, if any.
 * @return string
 */
function get_media_items($post_id, $errors)
{
    $attachments = array();
    if ($post_id) {
        $post = get_post($post_id);
        if ($post && 'attachment' === $post->post_type) {
            $attachments = array($post->ID => $post);
        } else {
            $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC'));
        }
    } else if (is_array($GLOBALS['wp_the_query']->posts)) {
        foreach ($GLOBALS['wp_the_query']->posts as $attachment) {
            $attachments[$attachment->ID] = $attachment;
        }
    }
    $output = '';
    foreach ((array) $attachments as $id => $attachment) {
        if ('trash' === $attachment->post_status) {
            continue;
        }
        $item = get_media_item($id, array('errors' => isset($errors[$id]) ? $errors[$id] : null));
        if ($item) {
            $output .= "\n<div id='media-item-{$id}' class='media-item child-of-{$attachment->post_parent} preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-{$id}' class='hidden'></div><div class='filename hidden'></div>{$item}\n</div>";
        }
    }
    return $output;
}

WordPress Version: 5.3

/**
 * Retrieve HTML for media items of post gallery.
 *
 * The HTML markup retrieved will be created for the progress of SWF Upload
 * component. Will also create link for showing and hiding the form to modify
 * the image attachment.
 *
 * @since 2.5.0
 *
 * @global WP_Query $wp_the_query WordPress Query object.
 *
 * @param int $post_id Optional. Post ID.
 * @param array $errors Errors for attachment, if any.
 * @return string
 */
function get_media_items($post_id, $errors)
{
    $attachments = array();
    if ($post_id) {
        $post = get_post($post_id);
        if ($post && $post->post_type == 'attachment') {
            $attachments = array($post->ID => $post);
        } else {
            $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC'));
        }
    } else if (is_array($GLOBALS['wp_the_query']->posts)) {
        foreach ($GLOBALS['wp_the_query']->posts as $attachment) {
            $attachments[$attachment->ID] = $attachment;
        }
    }
    $output = '';
    foreach ((array) $attachments as $id => $attachment) {
        if ($attachment->post_status == 'trash') {
            continue;
        }
        $item = get_media_item($id, array('errors' => isset($errors[$id]) ? $errors[$id] : null));
        if ($item) {
            $output .= "\n<div id='media-item-{$id}' class='media-item child-of-{$attachment->post_parent} preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-{$id}' class='hidden'></div><div class='filename hidden'></div>{$item}\n</div>";
        }
    }
    return $output;
}

WordPress Version: 4.3

/**
 * Retrieve HTML for media items of post gallery.
 *
 * The HTML markup retrieved will be created for the progress of SWF Upload
 * component. Will also create link for showing and hiding the form to modify
 * the image attachment.
 *
 * @since 2.5.0
 *
 * @global WP_Query $wp_the_query
 *
 * @param int $post_id Optional. Post ID.
 * @param array $errors Errors for attachment, if any.
 * @return string
 */
function get_media_items($post_id, $errors)
{
    $attachments = array();
    if ($post_id) {
        $post = get_post($post_id);
        if ($post && $post->post_type == 'attachment') {
            $attachments = array($post->ID => $post);
        } else {
            $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC'));
        }
    } else if (is_array($GLOBALS['wp_the_query']->posts)) {
        foreach ($GLOBALS['wp_the_query']->posts as $attachment) {
            $attachments[$attachment->ID] = $attachment;
        }
    }
    $output = '';
    foreach ((array) $attachments as $id => $attachment) {
        if ($attachment->post_status == 'trash') {
            continue;
        }
        if ($item = get_media_item($id, array('errors' => isset($errors[$id]) ? $errors[$id] : null))) {
            $output .= "\n<div id='media-item-{$id}' class='media-item child-of-{$attachment->post_parent} preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-{$id}' class='hidden'></div><div class='filename hidden'></div>{$item}\n</div>";
        }
    }
    return $output;
}

WordPress Version: 3.7

/**
 * Retrieve HTML for media items of post gallery.
 *
 * The HTML markup retrieved will be created for the progress of SWF Upload
 * component. Will also create link for showing and hiding the form to modify
 * the image attachment.
 *
 * @since 2.5.0
 *
 * @param int $post_id Optional. Post ID.
 * @param array $errors Errors for attachment, if any.
 * @return string
 */
function get_media_items($post_id, $errors)
{
    $attachments = array();
    if ($post_id) {
        $post = get_post($post_id);
        if ($post && $post->post_type == 'attachment') {
            $attachments = array($post->ID => $post);
        } else {
            $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC'));
        }
    } else if (is_array($GLOBALS['wp_the_query']->posts)) {
        foreach ($GLOBALS['wp_the_query']->posts as $attachment) {
            $attachments[$attachment->ID] = $attachment;
        }
    }
    $output = '';
    foreach ((array) $attachments as $id => $attachment) {
        if ($attachment->post_status == 'trash') {
            continue;
        }
        if ($item = get_media_item($id, array('errors' => isset($errors[$id]) ? $errors[$id] : null))) {
            $output .= "\n<div id='media-item-{$id}' class='media-item child-of-{$attachment->post_parent} preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-{$id}' class='hidden'></div><div class='filename hidden'></div>{$item}\n</div>";
        }
    }
    return $output;
}