You have to get a post’s attachments:
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => 5,
'post_parent' => $post_id,
) );
Related Posts:
- How to limit the number of posts that WP_Query gets?
- Should we trust the post globals?
- Random sort within an already sorted query
- How to know if get_posts() failed?
- WordPress Number of Posts Not Changing With posts_per_page
- How do I create Comma Separated list of attached image ids?
- How to add posts to wp_query result?
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- Search query – exact post title match
- posts_per_page doesnt work
- How to start with post number x?
- Exclude posts with empty post_content in wp_query
- Only display a certain number of posts, dependent on how many posts there are available in a query
- Improving WP_Query for performance when random posts are ordered
- Should $found_posts be returned as string in ‘found_posts’ filter hook?
- Get Posts that are in the current month or later
- Exclude the first ‘n’ number of posts of a tag from home page?
- posts_per_page option limits the number of Gallery items
- Why Query is returning empty array?
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- meta_value timestamp older than now
- Do not show children of a category
- Query for first 3 posts to change the look and feel
- Why posts array is empty?
- How to give classname to post if post has no content?
- Exclude some posts from displaying in wp_query based on some condition
- Related Posts function not working
- How to convert query sql to shortcode in wordpress?
- How Can I Always Display A Particular Post First Using WP_Query?
- WordPress Query – Display 5 posts (same post type), each from a given tag
- filter posts based on menu_order
- Show 5 posts and than 3 posts offset with pagination
- wp query custom orderby not custom field
- Sort / Filter Queries
- Advanced Post Display/Pagination/Ordering
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- Displaying Results From Custom Taxonomy Query
- WP_Query retrieve custom posts but not the post showing
- Wp_query WooCommerce products
- Add custom Attachment Display Setting for images
- Querying post from a multisite network
- Show related posts by category but ignore one category
- Post content being duplicated by the_content();
- How to extract images of post and pages excluding header and logo image in wordpress?
- How to add padding between posts
- Working Bootstrap Carousel Conversion to WP – Technical Questions
- Add few specific post ids to wp_query
- Check if post exists
- WP_Query posts_per_page ignored
- wp_query ‘s’ parameter does not work with custom post type
- Get all images out of the posts content
- WP Query – duplicated posts once including tags in search results
- How to retrieve the postID in a “image_send_to_editor” hook function?
- How do I use WP_Query to get a range of posts with custom fields that have numbers with letters in them?
- recent posts for different categories
- Change post order random through out the entire WordPress
- Set size for attachments
- Setup a custom dynamic post
- Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?
- Removing noindex posts from wp_query
- Using wp_list_pages() after calling query_posts()
- Why are my paginated posts always returning the same results?
- Query posts by Author and/or by Tag
- How to only publish posts with image in it
- Migrate posts from category and sub-category via SQL
- Use posts_where to exclude posts ids from wp_query
- Why does WordPress search returns same number of results for every search query?
- Sidebar limiting to 10 posts?
- Attachment image single page
- Adjust the order for returned posts
- Trim posts from WP-Query?
- Override WordPress core post-template.php block template
- Site/Post preview is not working on all social media
- how to add tags to post in the Loop?
- Change Old WordPress Post Date Year
- Display/Filter post using if else statement
- Search results for ACF data
- Query prints posts without specific categories
- Thumbnails and images in the blog post are not loading
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- Loop through all posts showing duplicates
- Manipulate query to show specific post
- WordPress text field in array problem
- My custom query is displaying random posts in random order
- Output wp_link_pages as raw url
- Get query result according to merged array
- Embed image in post from external url
- Is possible to do this from function.php
- Display the latest post from some selected authors
- SQL query to remove first image in all posts
- Multiple loops on a Search result page?
- WP_Query: Fetch posts that are in (category1 and not in category2), OR posts that are not in cagegory1
- Make division in post_query?
- Display one post randomly from category on home page
- How do I show the post title if an advanced custom field hasn’t been used?
- How add class the_content();?
- Import alt text in set_post_thumbnail
- Need to show birthday of custom post type(Famous people in this case) in elementor. Date of birth set in custom fields
- website images getting corrupt automatically