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.
Related Posts:
- Where does the gallery shortcode gets its attachments from?
- How to save media-form on custom tab
- Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails
- How can I bulk delete media and attachments using WP-CLI?
- Are captions stored anywhere?
- complex restriction of items in media library
- Edit image / Delete image link
- media_sideload_image file name?
- Get all posts (of any post type) an attachment is used in
- Detect if is image unattached
- Unattaching unlinked images
- How to get attachments for a specific post type?
- Show Post ID in “Find Posts or Pages” box in Media Library?
- Retrieving a custom link on an attachment
- how to test for attached image
- Can i hide the attachments from media which I uploaded from front end?
- ID of images from gallery
- Get the attachment URL on single.php
- Hide “Gallery Settings” and “Insert into Post” button from Attachment window
- Getting attachment images is cloning some of them
- Perform a custom (bulk) action in media view
- How to make a customized “Create Gallery” tab in the ‘Add Media’ window?
- Reorder “menu order” of attachments to another predefined order
- Add image attachment to post via coding?
- How to retrieve alt attribute for an attachment (uploaded image)?
- Ordering of gallery images without using shortcode in theme
- Custom Gallery HTML only working when images are attached to post/page
- Display random gallery images and its parent post title leading to parent post permalink
- Control attachments menu order with jQuery Sortable
- Is it possible to share media files between multiple WordPress sites?
- Open the Attachment Details popup
- Proper use of wp_get_attachment_image?
- how to get random media id from media gallery
- hide attached images of a post
- Upload multiple image with media_handle_upload with multiple file field [duplicate]
- WordPress Gallery Permalink Structure Displaying Incorrectly
- How do I get just the title from wp_get_attachment_image
- changing the default picture size link url
- Get an image from the media library. Struggling with the code?
- Programmatically Altering Gallery Link and image size?
- How is it possible that a gallery doesn’t have attachment ids?
- Media Library Mess After FTP … /uploads
- Media item permalink goes to source file instead of attachment.php
- wp_get_attachment_image_src calling wrong location
- Removing images deleted from uploads folder, from Media Library
- WP media attachment location vs permalink
- Removing delete permanently button in uploading files media
- Retrieve ONLY mp3s and set a variable for use in a playlist called by single.php template?
- Is there a way to add Reattach and Unattach links in image gallery?
- How to retrieve images contained in a post
- ID of images from gallery
- Gallery Thumbnail Layout Template
- Bulk delete media by year
- Media library upload hook
- How To Retrieve An Image Attachment’s Alt Text?
- Turn a URL into an Attachment / Post ID
- How to Fix HTTP Error When Uploading Images?
- How to manage attachment relationships for specific posts in WP 3.5+
- Programmatically adding images to media library
- Can I add a Category Metabox to attachment?
- Change attachment filename
- How to get attachment file name not attachment URL
- How to trigger a refresh in the media modal
- Custom collection in media manager?
- Delete Associated Media Upon Page Deletion
- Get all post attachments except featured image
- getting attachement images src and add classes
- Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
- Is it possible to query all posts that don’t have an attachment?
- Getting a taxonomy’s thumbnail url
- Check if post has attachments (not image)
- How to cleanly delete attachment but retain original file?
- How to paginate wordpress [gallery] shortcode?
- Changing attachment urls?
- Add custom class to attachment in media library grid mode
- Trying to hide buttons from Attachment window
- get_the_post_thumbnail() doesn’t taking style attribute
- Expanding new Media Uploader in WordPress 3.5
- How can I UN-attach media from a post?
- Uploading Multiple Attachments From Front-End With A Description
- Validate alt text for attachments?
- Remove duplicate attachments
- How could I add button next to “edit image” button in “Attachment Details”
- Applying automatic link class to images embedded to posts
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- How to call WP3.5 Media Library manager?
- How to get attachment caption (get_the_excerpt gives parent post excerpt) ?
- Is it possible to query specific WordPress Attachment files (.ppt & .pdf) and output them in a list?
- Password protect some uploaded files, so only logged-in users can view them
- How to single click to download image in single post
- What is the action hook for save media-form on gallery tab?
- delete attachment from front end
- Give attachments an archive page
- Customize WordPress Media Manager – Media Window
- How can I hide media library images from general users?
- custom fields for attachments?
- Insert Media – Attachment – Link to : Remove the “attachment page” option
- URL rewrite with add_rewrite_rule and attachment_id
- Saving Custom Field in Attachment Window in WordPress 3.5
- How to add media from front-end to an existing post?