Skip to content

Instantly share code, notes, and snippets.

@wwdboer
Created February 7, 2013 11:01
Show Gist options
  • Save wwdboer/4730303 to your computer and use it in GitHub Desktop.
Save wwdboer/4730303 to your computer and use it in GitHub Desktop.
WordPress: Get image attachments
function get_image_attachments( $size = 'thumbail', $ID ) {
$featured_image_id = get_post_thumbnail_id( $ID );
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_parent' => $ID,
'exclude' => $featured_image_id
);
$images = get_posts( $args );
$results = array();
if ( $images ) {
foreach ( $images as $image ) {
$results[] = wp_get_attachment_image( $image->ID, $size );
}
}
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment