Want more features on Pastebin? Sign Up, it's FREE!
Guest

Wordpress Caption and Description

By: a guest on Jul 26th, 2011  |  syntax: PHP  |  size: 1.75 KB  |  views: 150  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function retrieve_full_image_info($input){
  2.         $options = $input;
  3.         $numberofslides= $options['numberofslides'];
  4.         //Set an array to store all the image URLs from my options and the current index in the array.
  5.         $arrayofurls= array();
  6.         for ($i=0; $i<$numberofslides;$i++){
  7.                 $arrayofurls[$i]=$options['wdlmg_image_option'.$i];
  8.                 $arrayofurls[$i]['index']=$i;
  9.         }
  10.         //This below is what gets the attachment files.
  11.         $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null );
  12.         $attachments = get_posts( $args );
  13.         //Now we check if the urls we obtained from the media uploader with the attachment url
  14.         if (!empty($attachments)) {
  15.                 foreach ( $attachments as $post ) {
  16.                
  17.                 $id=$post->ID;
  18.                 $current = wp_get_attachment_url($id);
  19.                        
  20.                         foreach ($arrayofurls as $url){
  21.                         $wanted= $url['url'];
  22.                                 if($current == $wanted){
  23.                                         $index= $url['index'];
  24.                                         setup_postdata($post);                 
  25.                                         $options['wdlmg_image_option'.$index]['id']=$id;
  26.                                         $options['wdlmg_image_option'.$index]['title']=$post->post_title;
  27.                                         $three= wp_get_attachment_image_src($id);
  28.                                         $options['wdlmg_image_option'.$index]['width']=$three[1];
  29.                                         $options['wdlmg_image_option'.$index]['height']=$three[2];
  30.                                         $content= $post->post_content;
  31.                                         $options['wdlmg_image_option'.$index]['description']=$content;
  32.                                         //by default if caption is empty, its the description
  33.                                         $caption=$post->post_excerpt;
  34.                                         if($caption!=$content){
  35.                                                 $options['wdlmg_image_option'.$index]['caption']=$caption;
  36.                                         }//end if
  37.                                         //remove this url from list since we got its details.
  38.                                         unset($arrayofurls[$index]);   
  39.                                 }//end if
  40.                         }//end foreach
  41.                 }//end foreach
  42.         }//endif
  43.         return $options;
  44. }//end function
clone this paste RAW Paste Data