Hmm… Try altering your query a little to:
$args = array(
'post_parent' => $post_id,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ID',
);
$attachment = new WP_Query( $args );
$attachment = $attachment->posts;
Alternatively, you could use the following:
$attachments = get_children(
array(
'post_parent' => $post_id,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ID',
)
);
Related Posts:
- I would like to give special promotion for the first 100 posts in my blog? Can anyone tell me how to do that?
- is there a way to show the the post title after the image?
- wp_query with ajax
- Post images are not displayed in media library
- Ordering posts alphabetically by meta keys and title
- What is the proper use of guid for images in wp_posts?
- How to get posts published between a date and today?
- How can I retrieve multiple get_post_meta values efficiently?
- Export WordPress Posts and Meta Information in CSV format
- Replacing all attachment links in post with media file link
- Update all posts automatically when using post_meta
- Downloadable Documents
- Query posts distinct authors
- How to get previous 10 days post from a specific date – WP Query
- Setting post meta data to random value during post status transition / on publish
- Can’t show comments count per post outside loop
- Only display posts with comments
- Change post format using custom field
- Remove image from post also removes photo from media library
- Easy way to delete 70k posts and attached media?
- Filter Posts By Tag
- Can I set and show “important” post in my blog?
- Add custom field automatically (add_post_meta) with value based on number of words of article
- How to generate numbers indistinguishable for the IDs of the posts
- previewing my posts on static page?
- Exclude newest post from category X but show rest
- Reset Popular post query?
- Display posts with tag that matches current post title
- Why is querying posts messing up my pages?
- Category Foreach keeps looping?
- Insert woocommerce products programmatically with featured image and gallery
- wp-cli post create & media import issues
- Custom Posts Query and meta_query Sort Order
- Removal of Media Gallery pictures
- Automatically attach image to post if they have the same title
- Calling Different Custom Post Timestamps in a table
- Multi row post list
- wp_posts table: safely remove unused columns to save database storage
- Display Posts on Custom Page
- Remove Featured Image & All Media Uploaded to the Post
- Customize rel=canonical tag for single blog post
- Counter is skipping post when I still want it visible [closed]
- Is there any way to tell when wp_postmeta has been updated?
- Archive template combined with post slider and regular posts
- How to only publish posts with image in it
- Change post author without using wp_update_post()
- if in category but only with post meta
- Display a mixed list of posts and media
- How to give classname to post if post has no content?
- Display post number by category
- Updating post meta for checkbox
- Custom posts listing widget always returns 1 extra result
- WordPress post filter menu
- Bootsrap carousel for post
- Automatic blog page with custom design [closed]
- When sending a newsletter -not with wordpress- the server has 100% cpu [closed]
- Get postlist for each category using query_posts?
- How to save posts position on homepage after random function?
- Retrieve data from post meta meta_key having ‘_product_fq_image’ while having author_id and post type is PRODUCT
- Adding a meta box to determine the sidebar [closed]
- WordPress displays post on subcategory only
- Get post category as a separate string and url
- Trying to query all posts in category 4
- All images on one line for each post
- Delete Post but retain image of post [WP REST API]
- Pull in posts using post meta for REST API
- Site/Post preview is not working on all social media
- get posts, run a custom query, and join the results
- Getting image data from phone camera (MediaDevices.getUserMedia) into user post
- Displaying all posts from other sites on the network on one site
- Multisite how to display merged posts from two sites and sort by latest date?
- Private post caught in endless redirect loop
- What is proper filter or hook action to add data to the $post object?
- Blogposting Schema & Structured Data without plugin
- Display Updated Date Instead of Published Date
- How do you update post date (year only) in a separate custom field?
- Bulk Post update_post_meta
- Why does media_handle_sideload upload to last month’s folder?
- Re-order Category Meta-data
- Make recent post display recent updated, instead of recent published
- Grab meta data before post is saved
- Manipulate query to show specific post
- Blog posts not displaying on blog posts page
- alt of attached image in post / pages
- Get the correct meta_value with get_post_meta
- Disable Media uploader to users
- Add custom class to existing menu items from custom meta
- get “read more” with custom DB query like you would with WP Query
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- How do I control the fallback query after the original query returned cero posts?
- Adding a category at even positions on main loop with modified pagination
- How would I attach media/images to a post based on a ID stored in a each post’s custom field
- wp trim function not working
- Change from all posts to specific categories post on main page?
- If meta_key exists then don’t select this post?
- Count words for all posts by all authors
- Word count for all posts of all authors
- Do I need to create a multisite for querying posts from multiple WordPress sites?
- Dynamic archive of posts by date
- Optimize blog that serves hundred of images and videos