Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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() ){
    while($query->have_posts()){
        $query->the_post();
        $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() ) {
            $image_query->the_post();
            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

 
discard

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.