WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've found similar questions here, however I can't modify the answers to get images only from a certain post type - as the post type in those examples are "attachment" and not the name of a custom post type.

Is there a way to declare a custom post type argument as well?

Similar question, another similar question

share|improve this question
up vote 2 down vote accepted

Try this code in your template.

$query = new WP_Query( array( 'post_type' => 'custom-post', 'posts_per_page' => -1 ) );
if( $query->have_posts() ){
        $image_query = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'image', 'posts_per_page' => -1, 'post_parent' => get_the_ID() ) );
        while( $image_query->have_posts() ) {
            echo wp_get_attachment_image( get_the_ID() );

Replace custom-post with you custom post type.

share|improve this answer
Thanks. It's not just working, but it seems to exclude post thumbnails as well. Great. – elbatron Dec 2 '11 at 9:45
Correction: post thumbnails are not excluded. – elbatron Dec 6 '11 at 13:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.