I’m trying to display the first three attachment images in each post of a custom post type separately. I believe what I am looking for is a way to put the custom post type attachments into an indexed array so that I can then chose a few individual attachments from that array and display them in their own individual divs. So far the code is not functioning efficiently and does not display all the attachments in the posts. The code I’ve supplied is just a start to be expanded upon it has got me part way there, but I'm not sure how to proceed as my php knowledge is limited.
$attachments = get_children( array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => 'inherit',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ASC'
) );
foreach ( $attachments as $attachment_id => $attachment ) {
echo wp_get_attachment_image( $attachment_id, 'medium');
}