Title: kermit4wordpress's Replies | WordPress.org

---

# kermit4wordpress

  [  ](https://wordpress.org/support/users/kermit4wordpress/)

 *   [Profile](https://wordpress.org/support/users/kermit4wordpress/)
 *   [Topics Started](https://wordpress.org/support/users/kermit4wordpress/topics/)
 *   [Replies Created](https://wordpress.org/support/users/kermit4wordpress/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/kermit4wordpress/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/kermit4wordpress/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/kermit4wordpress/engagements/)
 *   [Favorites](https://wordpress.org/support/users/kermit4wordpress/favorites/)

 Search replies:

## Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)

 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Display the first image attached to post](https://wordpress.org/support/topic/display-all-images-attached-to-post/)
 *  Thread Starter [kermit4wordpress](https://wordpress.org/support/users/kermit4wordpress/)
 * (@kermit4wordpress)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/display-all-images-attached-to-post/#post-11015098)
 * Thanks so much catacaustic! All looks good and seems to be working. Here’s the
   slightly tweaked snipped to target just the older posts with the missing images
   in the two impacted categories:
 *     ```
       // Add all images to posts for pre 2012 Daily Photo categories
       add_action( 'genesis_before_entry_content', 'first_image' );
       function first_image () {
           $oldest_post_date = strtotime( the_date( 'Y-m-d', '', '', false ) );
           $oldest_cutoff_date = strtotime( '2012-09-10' );
           global $post;   // Assuming that this is in The Loop.
   
           $images = get_posts (array (
               'numberposts' => -1,
               'post_type' => 'attachment',
               'post_mime_type' => 'image',
               'post_parent' => $post->ID,
               'orderby' => 'menu_order',
               'order' => 'ASC'
           ));
       if( in_category( 'daily-photo' ) || in_category( 'daily-photo2' ) && ( $oldest_post_date < $oldest_cutoff_date )) {    
       foreach ($images as $image) {
   
               $image = wp_get_attachment_image_src ($image->ID, 'full');
        $imgwidth = $image[1];
           $wanted_width = 300; 
           if ( ($imgwidth > $wanted_width ) ) {
               echo '<img src="'.esc_url ($image [0]).'" alt="" />';
       	echo '<br/>';
           } else { 
               //do whatever you want
           }
   
           }
   
       }
       }
       ```
   
    -  This reply was modified 7 years, 5 months ago by [kermit4wordpress](https://wordpress.org/support/users/kermit4wordpress/).
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Display the first image attached to post](https://wordpress.org/support/topic/display-all-images-attached-to-post/)
 *  Thread Starter [kermit4wordpress](https://wordpress.org/support/users/kermit4wordpress/)
 * (@kermit4wordpress)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/display-all-images-attached-to-post/#post-11014397)
 * Further detail about the behavior I’m seeing, what it’s doing is inserting duplicate
   copies of the first attached image on each post a number of times equal to the
   number of images attached to each post, so on posts that have 5 attached images
   in the Media browser, it’s inserting 5 duplicate copies of the first image in
   the Media, but none of the other images (2-5)? It’s close but still a little 
   off.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Display the first image attached to post](https://wordpress.org/support/topic/display-all-images-attached-to-post/)
 *  Thread Starter [kermit4wordpress](https://wordpress.org/support/users/kermit4wordpress/)
 * (@kermit4wordpress)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/display-all-images-attached-to-post/#post-11014351)
 * Thanks, bcworkz. Understood. My apologies, and it won’t happen again. Regarding
   the code snippet catacaustic provided, I implemented a foreach loop, and now 
   it appears to be attempting to display ALL of the images attached to all posts
   on each post, instead of only displaying the particular images that belong to
   each particular post. Do you see what might be causing that?
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Display the first image attached to post](https://wordpress.org/support/topic/display-all-images-attached-to-post/)
 *  Thread Starter [kermit4wordpress](https://wordpress.org/support/users/kermit4wordpress/)
 * (@kermit4wordpress)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/display-all-images-attached-to-post/#post-11012574)
 * Thanks, catacaustic. This is helpful. I’m a newb with php and trying to fix a
   friend’s theme. After a hosting migration all of the posts in two categories 
   older than a specific date stopped displaying the attached images. There’s just
   the text from those posts in the post body but none of the image tags, but the
   respective images do still appear in the Media browser attached to each post,
   and the img tags can be manually reinserted back into the posts, but it’s hundreds
   of posts, so an automated way to just display the attached images on those old
   posts using a function would be great.
 * How would the code change if they want ALL of the images attached to each of 
   the posts in the two specific categories to appear in each of the posts that 
   has images attached to it? So say a post from April 10, 2012 has 5 images attached
   to it in Media, but none of them are inserted into the body of the post anymore?
 * _[compensation query redacted]_
    -  This reply was modified 7 years, 5 months ago by [bcworkz](https://wordpress.org/support/users/bcworkz/).

Viewing 4 replies - 1 through 4 (of 4 total)