I've been working for a couple days on a problem with the way my old attachment array functioned... I've been getting into the habit lately of writing posts ahead of time, and when I attach images to said posts those images show up in my array.
I want to limit the output to attachments that are children of published parents. Any ideas?
<?php
$valid_ext = array("gif", "png", "jpg");
$args = array(
'post_type' => 'attachment',
'numberposts' => 15,
'post_parent' => '$post->ID',
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $post) {
$ext = getFileExt(wp_get_attachment_url($post->ID, false));
if(in_array($ext, $valid_ext)) {
?>
<a href="<?php the_permalink(); ?>"><?php echo wp_get_attachment_image( $post->ID, 'thumbnail' ); ?></a>
<?php
}
}
}
?>