Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to get only current images of a post

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:

  1. I would like to give special promotion for the first 100 posts in my blog? Can anyone tell me how to do that?
  2. is there a way to show the the post title after the image?
  3. wp_query with ajax
  4. Post images are not displayed in media library
  5. Ordering posts alphabetically by meta keys and title
  6. What is the proper use of guid for images in wp_posts?
  7. Keep featured content post in homepage with original order
  8. How to get posts published between a date and today?
  9. ZIP up all images displayed in a [gallery] and offer as download link
  10. How to check if post meta key exists or not in wordpress database
  11. How to show related posts by category
  12. Delete Associated Media Upon Page Deletion
  13. How to add category to: ‘wp-admin/post-new.php’?
  14. the_author() returns empty string
  15. How can I retrieve multiple get_post_meta values efficiently?
  16. Code to make a post sticky
  17. How can you change the ‘Insert into Post’ title in the media button?
  18. How to allow hidden custom fields to be added from wp-admin/post.php?
  19. Display all posts from specific categories on a page
  20. media_handle_upload for local files?
  21. Post slugs and images cannot have same name?
  22. Export WordPress Posts and Meta Information in CSV format
  23. How do I detach images from posts?
  24. Delete duplicated wp_postmeta record
  25. How to exclude latest x posts from a paginated query?
  26. Will a large postmeta table slow a site down?
  27. Replacing all attachment links in post with media file link
  28. Update all posts automatically when using post_meta
  29. Display content from a specific category
  30. How to display posts by current user/author in a custom page template?
  31. Download external images if post is publish
  32. post_name empty after wp_insert_post
  33. How to batch update post content with custom post meta value
  34. Downloadable Documents
  35. Query posts distinct authors
  36. Change slug with custom field
  37. How to get previous 10 days post from a specific date – WP Query
  38. Number of posts per page setting is not working?
  39. Better post meta efficiency?
  40. WordPress Posts Out Of Order after 3.1 Update
  41. Setting post meta data to random value during post status transition / on publish
  42. Query only Posts from Both of Two Category?
  43. upload featured image from front end using wordpress add media button
  44. Insert custom div between posts
  45. Edit meta data does’t work with custom sql
  46. Can’t show comments count per post outside loop
  47. Only display posts with comments
  48. Get post embedded image caption
  49. Human Time Diff, change mins to minutes
  50. Order post by year DESC and month ASC
  51. Change post format using custom field
  52. WordPress get posts by date without query_posts
  53. How to Display Post View Count
  54. Does WP get all post_meta on POST page?
  55. How do I programmatically add an image to a post?
  56. Different amount of posts on homepage than paged pages
  57. Sanitizing `wp_editor();` Values for Database, Edit, and Display
  58. Remove image from post also removes photo from media library
  59. Exporting Data from WordPress into a flat table
  60. Adding Multiple Values to a Post Meta Key
  61. Featured Posts for Category Pages
  62. Using radio button meta data from a custom meta box
  63. Cannot Update A Post, 404 Error
  64. Function to show random posts from a category
  65. Hiding posts in a list from specified categories
  66. Easy way to delete 70k posts and attached media?
  67. How would I get 1 latest post from a query for 5 posts?
  68. PHP Notice error (when on 404 page)
  69. What Is meta_id In wp_postmeta?
  70. Filter Posts By Tag
  71. Can I set and show “important” post in my blog?
  72. Checking if a post with certain meta value exists
  73. Exclude posts with empty post_content in wp_query
  74. How to permanently delete a post meta entry?
  75. Add custom field automatically (add_post_meta) with value based on number of words of article
  76. How to generate numbers indistinguishable for the IDs of the posts
  77. Improving WP_Query for performance when random posts are ordered
  78. Modify WP_Post before processing
  79. Save re-arranged draggable post items to wordpress database
  80. Create dropdown list post
  81. Change post_date to post_modified date on post template?
  82. previewing my posts on static page?
  83. Exclude newest post from category X but show rest
  84. Reset Popular post query?
  85. Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
  86. Inserting custom data to the_post() during loop
  87. How To Get Posts With A Specific Word
  88. Too many connections to server
  89. Why WP_Query(‘showposts=5’) shows only 1 post?
  90. How can I sort posts by the date and a custom meta field?
  91. Errors when uploading images in WP 3.5
  92. Get Meta Key Value While Saving Post
  93. Display posts with tag that matches current post title
  94. Why is querying posts messing up my pages?
  95. Display all posts that were published before full post on single.php
  96. Category Foreach keeps looping?
  97. Insert woocommerce products programmatically with featured image and gallery
  98. How can I get the media inside a post?
  99. Blog post per page setting conflicting with custom WP_Query?
  100. How to exclude latest x posts from a paginated query?
Categories posts Tags media, media-library, post-meta, posts, query-posts
How to stop showing menu in static home page
Why do comments only come through on 2 of my posts and not the others?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress