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

Get attachment meta (I need attachment ID, unsure how to find it)

“Attachments” aren’t meta data. That is why you can’t retrieve them with get_post_meta(). “Attachments” are a post type that is attached to the parent post. You need to pull the attachment posts that have you post set as parent, and then use those IDs to get the attachment meta.

$args = array(
    'post_parent' => $post->ID,
    'post_type'   => 'attachment', 
    'numberposts' => -1 
);
$children = get_children($args);

foreach ($children as $c) {
  $att = wp_get_attachment_metadata( $c->ID, $unfiltered );
  var_dump($att);
}

Related Posts:

  1. Make a custom field in admin post.php read only
  2. How to add a checkbox element to attachments editor with example
  3. How to sanitize select box values in post meta?
  4. Strategy to get post meta for use outside the loop
  5. Set Expiration Date of a Post from the Frontend with wp_insert_post
  6. Change loop order via form or link (jquery, not URL)
  7. Why is unfiltered html allowed in custom fields for author / contributor roles?
  8. Using the theme options to change background
  9. wp_editor() usage in custom meta box
  10. Is there a need for nonce with Post Metabox?
  11. Custom Field returning Numerical Value for Image rather than URL
  12. Metadata Query when storing data as array possible?
  13. Custom post fields
  14. How can I create a list of page titles from custom meta values?
  15. How do I Add images uploaded in the post to a default custom field
  16. Custom Field created in add_meta_boxes reappearing itself again in the default Custom Metabox
  17. How do you replace content generated by custom fields with custom blocks in Block Editor?
  18. Sort wp_query by sum of two meta fields
  19. What’s the best practice way of handling custom fields in different post formats?
  20. Custom page template with custom fields
  21. Wp Super Cache stops the update of a Post Meta
  22. Where WordPress Stores The Custom Fields Values
  23. How to show specific post meta?
  24. Running a function on post update with new post meta
  25. What is the best way to build home pages with a lot of sections for distributable themes [closed]
  26. How to add post meta fields to an article’s as meta elements
  27. Is it possible to set a variable for get_post_meta?
  28. Injecting pre-defined text from custom page template to editor
  29. Let user to add input fields on theme option page
  30. How to use shortcode inside of shortcode in theme
  31. Add image URL automatically to custom field?
  32. How can I sort my loop based on meta data, using a form?
  33. Related Post Category Filter
  34. How can I add a field for featured image on backend of a custom Taxonomy?
  35. How to fix a conflict cause by my theme with Woocommerce and/or Gravity Forms?
  36. I want to change the author name
  37. How to add custom field option with menu?
  38. Change default options on attachment page
  39. Add custom field to existing meta box?
  40. Add Field To All Pages
  41. After a while attachment meta data is missing “sizes” data
  42. Why is my Toggle field not showing in Gutenberg?
  43. How do I access the current post object within a block theme template or pattern?
  44. Menu items description? Custom Walker for wp_nav_menu()
  45. How to define and link full path to css located at a random folder on header.php
  46. Sizing screenshot.png without losing aspect ratio
  47. Software for WordPress Theme and Plugin Development? [closed]
  48. When to use is_home() vs is_front_page()?
  49. What is the preferred way to add custom javascript files to the site?
  50. Get the blog page URL set in Options
  51. How to create .pot files with POedit?
  52. How do I get the theme URL in PHP?
  53. Why when I submit a form in wordpress it loads a 404 page though URL is correct
  54. what is the correct way to compare dates in a WP query_posts meta_query
  55. What is the constant WP_USE_THEMES for?
  56. Worthwhile to restrict direct access of theme files?
  57. How Do I Protect My Premium WordPress App Theme from Copying?
  58. How to detect mobile devices and present them a specific theme?
  59. Can I exclude a post by meta key using pre_get_posts function?
  60. Advanced search form with filters for custom taxonomies and custom fields
  61. Using wp_add_inline_style without a stylesheet
  62. How to update custom fields using the wp_insert_post() function?
  63. How to add posts to custom menus?
  64. WordPress Theme Preview Image
  65. How To extend WP_Customize_Control
  66. How to display value of custom fields in page
  67. What is the difference between front-page.php and home.php? [duplicate]
  68. Can wp_query return posts meta in a single request?
  69. How can I get page slug
  70. Does the functions.php file ever get called during an AJAX call? Debug AJAX
  71. When to use _e and __ for the translation?
  72. What is a Theme textdomain?
  73. How to show a custom meta box on the “Quick Edit” screen?
  74. How to add CSS class to custom logo?
  75. How to add custom css file in theme?
  76. How important is it to enqueue a theme’s stylesheet?
  77. CSS not updating in browser when I change it
  78. Display Search Result Count
  79. wp_nav_menu(), how to change class?
  80. theme path in javascript file
  81. Is wp_is_mobile() effective?
  82. Display Menu Name using wp_nav_menu
  83. Making update notification functionality for my themes
  84. What questions do you ask when asked to give an estimate on theme development?
  85. How to remove dashicons.min.css from frontend?
  86. How do I remove a pre-existing customizer setting?
  87. Minimum Template Files for Theme Development
  88. What’s the difference between home.php and index.php?
  89. pass object/JSON to wp_localize_script
  90. get_template_part vs action hooks in themes
  91. Theme Activate Hook
  92. Solutions for generating dynamic javascript / CSS
  93. wp_redirect() – headers already sent
  94. Can I create my own “Recent Posts” widget or customize the existing one?
  95. Custom single template for a specific category
  96. how can I add an icon/image for a child theme?
  97. How can I add a URL field to the attachments window?
  98. The the_post_thumbnail without srcset?
  99. The proper way to include/require PHP files in WordPress
  100. Get the first image from post content (eg.: hotlinked images)
Categories theme-development Tags custom-field, post-meta, theme-development
$count_posts->draft & published
Get All In One SEO Pack to use custom field instead of Content

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