Get all posts with attachments
-
Hi!
I’m using two nested loops to get all posts with one or more attachments:
$wp_query = new WP_Query(array('post_type' => 'magazine', 'paged' => $paged, 'posts_per_page' => 10 )); while ( have_posts() ) : the_post(); $args = array('order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'application/zip, application/pdf', ); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $attachment) { echo wp_get_attachment_link($attachment->ID); } } endwhile;
I was wondering if there’s a way to do the same with just one loop.
Thanks in advance
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Get all posts with attachments’ is closed to new replies.