Try this code and replace custom-post
with your custom post type.
$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() );
}
}
}
Related Posts:
- What is the use of to_ping and pinged column?
- Prevent Authors from viewing each others Posts
- Removing filter dropdown in posts table (in this case Yoast SEO)
- Listen to Post action
- Export WordPress Posts and Meta Information in CSV format
- How to add post count to wp_nav_menu?
- Posting From Apple Aperture?
- How to know if get_posts() failed?
- Show related posts by category but ignore one category
- Replacing all attachment links in post with media file link
- Post content being duplicated by the_content();
- how to show all post in my page-grid.php template page
- How to add padding between posts
- eBooks download website, page or post?
- Remove whitespace at the end of posts?
- Add few specific post ids to wp_query
- Disable REST API for a user ROLE
- Add filter-by-tag in the all posts admin console page
- Can I hide a specific post from latest posts page?
- Latest 5 posts (custom post type), each post different CSS
- Add scripts on custom post add/edit pages Not Working
- Understand post type
- How can I show wordpress posts based on author?
- previewing my posts on static page?
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Avoid duplicate post from same Taxonomy
- Post revisions disappeared (for some posts)
- Replace ‘published on date’ with ‘modified on date’ on Posts
- How to display category from recent posts?
- Can I divide the pages into categories?
- Display featured products by category
- Best way to assign post position in a news site homepage? (no categories, no sticky posts)
- WordPress Retrieve Post by Title
- How to include the latest post of a specific category on a matching page
- post categories
- API endpoint to get most-read and popular posts
- Is it possible to run wp_kses on all posts?
- CSS: How can I show a photo beyond the template’s column, but contained within the browser window? [closed]
- Responsive images with custom image size
- Can I search posts and pages for css classes?
- Take a received feedback item, turn it into a post
- how to get post order by post id wp_query?
- How to display all posts divided/ordered by post date? [closed]
- store posts_id of category into a varable?
- Multiple comment forms on a single page
- Why I can not I use the variable outside my function?
- If contributor has published 2 or more posts then show otherwise hide
- The_excerpt() doesn’t parse – how to change that?
- Extracting relevant tags associated with that particular single post only
- How to Assign / Move all Deleted post to a category
- Display a mixed list of posts and media
- How to get WordPress post ID of last visited page?
- Why in my query is display two title?
- Custom Articles page only showing a limited number of posts per page
- Custom posts listing widget always returns 1 extra result
- Show posts by quarter
- Automatic blog page with custom design [closed]
- Make ‘blog’ page show content as well as posts underneath it
- Cant’ Grab WordPress Built-in Posts Through Loop
- Sidebar limiting to 10 posts?
- Attachment image single page
- Short link to read complete post
- Display content between two dates?
- Automatic duplicate/copy of post to a related page in WordPress
- Change Old WordPress Post Date Year
- WordPress doesn’t save or publish new posts
- Yoast breadcrumb URL shows category instead of the page
- How to fix wordpress blog post error? Can anyone help to fix this issue?
- Query prints posts without specific categories
- Private post caught in endless redirect loop
- Foreach issue in get_posts function
- Contributor edits published post and sends for review – post is made private?
- Why does my “Add New Post” page have an old post in it?
- link to edit a post has empty target
- migrate only recent posts
- Is it possible to make a custom post that adds multiple pages?
- post categories – how to show only categories with a specific parent id
- Creating a “category” of featured posts
- How do I make it so that new posts within a certain category go into a certain page?
- Post URL duplication adds numerical value
- Is it possible to display QUICK EDIT as default for all posts in wp-admin/edit.php page?
- List Authors For Current Category
- cleaning out posts that don’t exist anymore but links are still there
- some posts being displayed as pages
- Assign specific ads to specific categories/posts
- Reading Setting Not Working for Number of Posts
- 404 for some custom taxonomy not ALL taxonomy
- Add tags to post before it’s created
- Body text disappearing in random posts
- Get part of a page url
- can’t post immediately
- Displaying posts on Homepage
- Adding a time stamp on post view
- Where are my posts linked to? I keep getting a Not Found Error, and I have no single.php page
- The post order is different for logged-in and non-logged-in users? [closed]
- Display one post randomly from category on home page
- save_post not working
- How to show all Posts Image, Title and 3 line description on main page?
- CSS code for “inserting a custom post divider” after each post
- How to monitor the first publish date?