Is there a way to get attachments with WP_Query?
It seems to work only with get_posts():
$attachments = new WP_Query('post_type=attachment'); // not working
$attachments = query_posts('post_type=attachment'); // not working
$attachments = get_posts('post_type=attachment'); // works
var_dump($attachments);
What about using get_children?
For example, display thumbnail image for post in loop:
<?php
$images = get_children(
array(
'post_parent' => $post->ID,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order'
)
);
if ( $images ) {
foreach ( $images as $id => $image ) {
$img = wp_get_attachment_thumb_url( $image->ID );
$link = get_permalink( $post->ID );
print "\n\n" . '<img class="thumb" src="' . $img . '" alt="" />';
}
}
?>