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 get attachment file name not attachment URL
- How to cleanly delete attachment but retain original file?
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- How can I display custom fields value from attachment media?
- Add an image gallery to a custom post type?
- Use Media Library to manage galleries like Nextgen (with folders, albums, collections, tags, categories, terms…)
- How to Add a Custom Colum on Thickbox Media Gallery Tab?
- attachment url rewrite
- Get the title and URL of the attachment parent post
- Confused with attachment mimetype order
- query attachment images … if no attachments -> get attachments of parent page?
- Replacing with(out) regex link to attachment by links to files
- rename attachments based on parent-post-title on upload
- Rename attachments during upload no matter what filetype
- save_post not working with attachments
- Link all WordPress images size
- Displaying Post Attachment(s) at Top of single.php
- Detach an image from a page using php
- Get the path of the first attached media (single.php)
- custom admin thumbnail for videos, not getting post’s id?
- Image Gallery Numbers for 3.5
- How to delete a custom file from upload directory when deleting its post
- How to filter a post in the Tag Cloud widget, using tags of a media library image attached to the post?
- Query to only return the 2 newest post attachments (images)?
- Clean up images, delete unused image sizes attached to a post type
- What is the best way to store thumbnails for a non-image attachment?
- problem in uploading attachment to custom directory
- Add attachment for all images in post
- What will happen if I delete all my attachment type posts from database?
- filter get_children to return all mime types EXCEPT ‘x’
- Weird string offset errors when displaying post attachments
- Links to my uploads went crazy
- How to add a caption to an image attachment in a file list?
- Possible to add “Even/Odd Classes” to image attachments via wp_get_attachment_image?
- Can’t sort get_posts by post_mime_type
- How to list “invisible” Auto Drafts?
- How to add media from front-end to an existing post and edit file title
- Auto delete content in specific folder inside media library
- Media Categories as Classes on WordPress Gallery Shortcode
- Attachment Metadata inside of Loop
- Get video attachment ID and display length
- Add link to attachment for old posts
- Move caption in on attachment page
- WordPress gallery image link gives 404 when not logged in