I'm making a widget that shows a set of images from recent custom posts. I want to run the following query:
SELECT p.*
FROM wp_posts p
WHERE post_type='attachment'
AND post_mime_type LIKE 'image%'
AND post_parent IN (
SELECT ID
FROM wp_posts
WHERE post_type ='my_custom_post_type'
)
ORDER BY post_date DESC
LIMIT 10;
and receive an array of attachment objects. I am unclear on the canonical WordPress method for doing something like this. Where should I start?