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?
- Keep featured content post in homepage with original order
- How to get posts published between a date and today?
- ZIP up all images displayed in a [gallery] and offer as download link
- How to check if post meta key exists or not in wordpress database
- How to show related posts by category
- Delete Associated Media Upon Page Deletion
- How to add category to: ‘wp-admin/post-new.php’?
- the_author() returns empty string
- How can I retrieve multiple get_post_meta values efficiently?
- Code to make a post sticky
- How can you change the ‘Insert into Post’ title in the media button?
- How to allow hidden custom fields to be added from wp-admin/post.php?
- Display all posts from specific categories on a page
- media_handle_upload for local files?
- Post slugs and images cannot have same name?
- Export WordPress Posts and Meta Information in CSV format
- How do I detach images from posts?
- Delete duplicated wp_postmeta record
- How to exclude latest x posts from a paginated query?
- Will a large postmeta table slow a site down?
- Replacing all attachment links in post with media file link
- Update all posts automatically when using post_meta
- Display content from a specific category
- How to display posts by current user/author in a custom page template?
- Download external images if post is publish
- post_name empty after wp_insert_post
- How to batch update post content with custom post meta value
- Downloadable Documents
- Query posts distinct authors
- Change slug with custom field
- How to get previous 10 days post from a specific date – WP Query
- Number of posts per page setting is not working?
- Better post meta efficiency?
- WordPress Posts Out Of Order after 3.1 Update
- Setting post meta data to random value during post status transition / on publish
- Query only Posts from Both of Two Category?
- upload featured image from front end using wordpress add media button
- Insert custom div between posts
- Edit meta data does’t work with custom sql
- Can’t show comments count per post outside loop
- Only display posts with comments
- Get post embedded image caption
- Human Time Diff, change mins to minutes
- Order post by year DESC and month ASC
- Change post format using custom field
- WordPress get posts by date without query_posts
- How to Display Post View Count
- Does WP get all post_meta on POST page?
- How do I programmatically add an image to a post?
- Different amount of posts on homepage than paged pages
- Sanitizing `wp_editor();` Values for Database, Edit, and Display
- Remove image from post also removes photo from media library
- Exporting Data from WordPress into a flat table
- Adding Multiple Values to a Post Meta Key
- Featured Posts for Category Pages
- Using radio button meta data from a custom meta box
- Cannot Update A Post, 404 Error
- Function to show random posts from a category
- Hiding posts in a list from specified categories
- Easy way to delete 70k posts and attached media?
- How would I get 1 latest post from a query for 5 posts?
- PHP Notice error (when on 404 page)
- What Is meta_id In wp_postmeta?
- Filter Posts By Tag
- Can I set and show “important” post in my blog?
- Checking if a post with certain meta value exists
- Exclude posts with empty post_content in wp_query
- How to permanently delete a post meta entry?
- 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
- Improving WP_Query for performance when random posts are ordered
- Modify WP_Post before processing
- Save re-arranged draggable post items to wordpress database
- Create dropdown list post
- Change post_date to post_modified date on post template?
- previewing my posts on static page?
- Exclude newest post from category X but show rest
- Reset Popular post query?
- Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
- Inserting custom data to the_post() during loop
- How To Get Posts With A Specific Word
- Too many connections to server
- Why WP_Query(‘showposts=5’) shows only 1 post?
- How can I sort posts by the date and a custom meta field?
- Errors when uploading images in WP 3.5
- Get Meta Key Value While Saving Post
- Display posts with tag that matches current post title
- Why is querying posts messing up my pages?
- Display all posts that were published before full post on single.php
- Category Foreach keeps looping?
- Insert woocommerce products programmatically with featured image and gallery
- How can I get the media inside a post?
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?