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
- How to make WP_Query faster when getting a post from one year ago?
- Setup a custom dynamic post
- Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?
- How to verify wp user password by sql query in wp? [closed]
- Removing noindex posts from wp_query
- WP Query – Posts Per Page not working in combination with category__in
- I have a site where attachments in the wp_posts table have guid values of guid, how did this happen?
- CSS: How can I show a photo beyond the template’s column, but contained within the browser window? [closed]
- Get all attachment by post excluding featured and content inside
- Ajaxify This Code
- wp-cli post create & media import issues
- How to filter my search in post if contains a word in title, content or excerpt?
- How to return another post than requested
- filter RSS feed in URL
- Pausing and Resuming WP_Query results
- How to do set post permalinks using 6 digit random unique function?
- Select only post id and meta value with WP_Query
- WordPress custom Query for Posts in Category display posts multiple times
- Lost draft under all posts and drafts
- Get user categories with most posts in it
- Get attachments for posts that belongs to a specific category
- Random ajax load only works with posts_per_page set to -1
- Prioritize posts in query by meta keys?
- List all categories with featured image from post?
- How to : pagination in 3 different custom loops on the same page
- get query() without post content?
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- How can I setup a relationship using categories in WordPress?
- Query posts and return XML
- Get all images in post and comments like Twitter before post title
- how to change the number of posts returned in a specific loop without making it global?
- Query Posts With Over 1000 Views
- Show only posts with images and a fixed amount of posts
- Issue where WP Featured Image will not display
- List authors with the last post title and order by last post date
- How to order posts by meta_value and title
- How would one change the default url structure of attachments?
- How i can limit period of post publication?
- wp_query random post
- wp_posts table: safely remove unused columns to save database storage
- Query Posts by Custom Field
- Adding a blog archive with pagination using WP_Query
- How to get Tags with specific post id
- How to setup a query to output posts by groups of five?
- Redirect to another page using contact form 7? [closed]
- Better wordpress attachment query than this
- how can i change WP main archives loop to sort by name or title
- If statement to check if post has image
- Using wp_list_pages() after calling query_posts()
- how to get post order by post id wp_query?
- Possible to alternate between two loops
- Gather posts into a cart/lightbox and share with another user
- Exclude current custom post on single post
- Nested WP_Query breaking loop
- WordPress query_posts by tag doesn’t work anymore(?)
- Dynamically switch template on click
- How to get posts and comments amount per hour, per year and per month?
- Get all custom post types excepted some…
- Thumbnail Image to go in the post aswell
- Get all comments of author’s posts