Title: Multiple image sizes within the same foreach loop?
Last modified: August 30, 2016

---

# Multiple image sizes within the same foreach loop?

 *  Resolved [dansz](https://wordpress.org/support/users/dansz/)
 * (@dansz)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/multiple-image-sizes-within-the-same-foreach-loop/)
 * I love this plugin. I use it with almost every project – but I’m always running
   into issues handling images.
 * I’ve got a project where I’m using image_advanced for users to populate a jquery
   slider on the front end. Each uploaded image shows up as a slider image (large)
   and an thumbnail (thumbnail).
 * Can I pull values for both sizes from a single array? Or is there a comprehensive
   way of merging the large array with the thumbnail array?
 * The following code is not valid, but it might help show what I’m going for.
 *     ```
       $images = rwmb_meta( 'savino_gallery', 'type=image&size=large' );
       $thumbs = rwmb_meta( 'savino_gallery', 'type=image&size=thumbnail' );
   
       foreach ($images as $image && $thumbs as $thumb) {
            echo "<li data-thumb='{$thumb['url']}'><img src='{$image['url']}' width='{$image['width']}' height='{$image['height']}' alt='{$image['alt']}' /></li>";
       }
       ```
   
 * This may just be a matter of tweaking php syntax, but I’m not sure where to go
   from here.
 * [https://wordpress.org/plugins/meta-box/](https://wordpress.org/plugins/meta-box/)

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

 *  Plugin Author [Anh Tran](https://wordpress.org/support/users/rilwis/)
 * (@rilwis)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/multiple-image-sizes-within-the-same-foreach-loop/#post-6306012)
 * I think your code is good, but you can add a small optimization like this:
 *     ```
       $images = rwmb_meta( 'savino_gallery', 'type=image&size=large' );
   
       foreach ($images as $id => $image) {
           list( $thumb ) = wp_get_attachment_image_src( $id, 'thumbnail' );
           echo "<li data-thumb='{$thumb}'><img src='{$image['url']}' width='{$image['width']}' height='{$image['height']}' alt='{$image['alt']}' /></li>";
       }
       ```
   
 *  Thread Starter [dansz](https://wordpress.org/support/users/dansz/)
 * (@dansz)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/multiple-image-sizes-within-the-same-foreach-loop/#post-6306029)
 * Works perfectly! Thank you!

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

The topic ‘Multiple image sizes within the same foreach loop?’ is closed to new 
replies.

 * ![](https://ps.w.org/meta-box/assets/icon-128x128.png?rev=1100915)
 * [Meta Box](https://wordpress.org/plugins/meta-box/)
 * [Support Threads](https://wordpress.org/support/plugin/meta-box/)
 * [Active Topics](https://wordpress.org/support/plugin/meta-box/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/meta-box/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/meta-box/reviews/)

## Tags

 * [images](https://wordpress.org/support/topic-tag/images/)

 * 2 replies
 * 2 participants
 * Last reply from: [dansz](https://wordpress.org/support/users/dansz/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/multiple-image-sizes-within-the-same-foreach-loop/#post-6306029)
 * Status: resolved