get_media_items

Retrieve HTML for media items of post gallery.

Description

(string) get_media_items( (int) $post_id, (array) $errors ); 

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.

Returns (string)

Parameters (2)

0. $post_id — Optional. (int)
Post ID.
1. $errors (array)
Errors for attachment, if any.

Usage

  1. if ( !function_exists( 'get_media_items' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4. // Optional. Post ID. 
  5. $post_id = -1; 
  6.  
  7. // Errors for attachment, if any. 
  8. $errors = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_media_items($post_id, $errors); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/media.php  
  1. function get_media_items( $post_id, $errors ) { 
  2. $attachments = array(); 
  3. if ( $post_id ) { 
  4. $post = get_post($post_id); 
  5. if ( $post && $post->post_type == 'attachment' ) 
  6. $attachments = array($post->ID => $post); 
  7. else 
  8. $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') ); 
  9. } else { 
  10. if ( is_array($GLOBALS['wp_the_query']->posts) ) 
  11. foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) 
  12. $attachments[$attachment->ID] = $attachment; 
  13.  
  14. $output = ''; 
  15. foreach ( (array) $attachments as $id => $attachment ) { 
  16. if ( $attachment->post_status == 'trash' ) 
  17. continue; 
  18. if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) ) 
  19. $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>"; 
  20.  
  21. return $output;