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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0