I can get a list of the most recent image attachments like so:
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => $number,
'post_mime_type' => 'image'
) );
This returns all images that have been recently uploaded, whether they are attached to a post or page, or unattached through the Media menu.
What I'd like is to limit that list to only images that are attached to a custom post type I've created. (The custom post type is not that important; the same question could be: 'only images attached to Posts' or 'only images attached to Pages.')
I realize I could test each image after running the above query and eliminate any whose parent is not the right post type, but I want to return a specific number of images ($number
), and this method could eliminate some or all of the returned images!