[wp-trac] [WordPress Trac] #10657: Posts column "post_parent" should be an array when "post_type" is "attachment"

WordPress Trac wp-trac at lists.automattic.com
Wed Aug 19 23:29:30 UTC 2009


#10657: Posts column "post_parent" should be an array when "post_type" is
"attachment"
-----------------------------+----------------------------------------------
 Reporter:  morgansson       |       Owner:                                           
     Type:  feature request  |      Status:  new                                      
 Priority:  normal           |   Milestone:  Unassigned                               
Component:  Media            |     Version:                                           
 Severity:  normal           |    Keywords:  post_parent, post_type, attachment, array
-----------------------------+----------------------------------------------
 For example if you have uploaded an image to a post, and then you want to
 re-use it in another post, that image "post_parent" cell in the database
 will be the first "post_id" where it was added only and not both. I think
 it should be an array for many reasons, and because I don't see any
 problem if this changes this way.
 ----
 I'm actually using this code to get the thumbnails for each post in the
 main page of my site.

 {{{
 function bdw_get_images($imagesize='large') {
     global $post;
     // Get the post ID
     $iPostID = $post->ID;
     $image = null; // Clear the value from the previous post
     // Get all attachments from the post ID with type image
     $attachments =&
 get_children(array('post_parent'=>$iPostID,'post_type'=>'attachment','post_mime_type'=>'image'));

     // If attachments are found...
     if ($attachments == TRUE) {
         // ... go through all of them
         foreach($attachments as $att) {
             // Get the image source for every image attachment found
             // Post_ID, Size ('thumbnail', 'medium', 'large', 'full' or an
 Array), Icon (true/false)
             $image =
 wp_get_attachment_image_src($att->ID,$imagesize,false);
             break; // Comment this line to get all images inside the post
         }
     }
     if (isset($image)) {
                 return $image[0];
         } else {
                 return false;
         }
 }
 }}}
 The problem here is that the thumbnail is only showing on the first post
 where it was attached to.
 I know there are other ways to do what I want, but I just think this is
 the most semantic and the agile way.

 I hope you could implement the change in further WordPress versions
 because it might open a lot of new possibilities on posting.

 Thanks for your time.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/10657>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list