I would like to query for images attached to ALL posts of certain custom post type (e.g. ‘gallery’).
I can’t see a way to do this by using only WP_Query. The workaround would be to query for all posts of a custom post type, then get the attachments and stuff everything together. But i don’t think that this would be a good solution, because you end up doing multiple queries for something that should be done in one.
Please help =)
Try this code and replace
custom-post
with your custom post type.I have added rand and posts_per_page to the last answer