WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a WordPress network and am looking for a way to pull recent images from the sub blogs, but I am having some trouble doing so.

What is the easiest way to make this happen?

share|improve this question
Your question is very vague. Please explain in detail what you want to do. – toscho Mar 11 '12 at 2:09
up vote 2 down vote accepted

Use switch_to_blog to switch blog contexts to a specific blog ID. From there on it's all down to get_posts of the attachment type. And switching back to the current context with restore_current_blog.

Something like this:

switch_to_blog( $blog_id );

$args = array( 'post_type' => 'attachment', 'numberposts' => 5, 'orderby' => 'post_date', 'order'=> 'ASC' );

foreach ( get_posts( $args ) as $attachment ) {
    echo wp_get_attachment_image( $attachment->ID );

share|improve this answer
Worked very well and thank you for the direction. To add uniformity to the images I used the additional parameters for wp_get_attachment_image(); to include the thumbnail size. – jw60660 Mar 11 '12 at 17:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.