I’m looking for a method to pull thumbnails as well as the source for the large image (to be used as a mini gallery) that pulls image attachments from multiple specified post ID’s.
Basically a query for post attachments that combines all the images into one mini gallery.
I’ve seen how to pull image attachments from a single post, but no idea how to pull image attachments from multiple posts?
In other words, can we pull image attachments from a specified array of posts?
Below is the code i’m using to pull ALL attachments throughout the site:
<?php
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null );
$attachments = get_posts( $args );
if ($attachments) {
foreach ( $attachments as $post ) {
setup_postdata($post);
the_title();
the_attachment_link($post->ID, false);
the_excerpt();
}
}
?>
After much searching I had to conclude there is no elegant way to do this with just one WP_query. Instead you can call a new query for each post_id and combine the resulting attachment ids into one array. Use this array for your further purposes.