Making a loop of attachments, using post__in array?
-
Hi there
I am creating a new instance of the WP_Query class to create a simple custom loop of attachments. the idea is that the administrator can add an array of custom fields that refer to media attachments as resources. So, they would enter “Resource ID” and the value would be the ID number of the upload.
So far so good. The loop works just fine when I specify in my arguments array (which I’m passing into my class call) and have ONE attachment called by using p => $att_id
I would like to insert an array instead for attachment ids, so am using post__in. Here is my code, but once I do it this way, nothing happens.
$resources = get_post_meta($id, "Resource ID", false); // Allow more than one resource; returns an array $content = ''; if($resources){ $att_ids = array(); foreach($resources as $resource){ $resource = trim($resource); $att_ids[] = $resource; } $args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post__in' => $att_ids ); $att_query = new WP_Query($args); if( $att_query->have_posts() ): while( $att_query->have_posts() ): $att_query->the_post(); $content .= 'Blah blah blah'; endwhile; endif; // etc. etc.Any guidance gratefully received!
John
The topic ‘Making a loop of attachments, using post__in array?’ is closed to new replies.