1

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

2

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.

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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