There are two methods:
-
$attachment_meta = get_post_meta( $post->ID, '_wp_attachment_meta', true );Will return an
array():$width = $attachment_meta['width'];That
trueas the third parameter is especially important in this case, since the metadata being queried is a serialized array. You need to return it as single, or you’re going to get an array returned, except the first item in that array will be the serialized array. Messy. Just passtrue, and you’ll get your unserialized array returned. -
This function is sort of a wrapper for the above
get_post_meta()call.$attachment_meta = wp_get_attachment_metadata( $post->ID );
In both cases, $post is the attachment, not the parent post to which the attachment is uploaded.
Related Posts:
- Retrieving post meta array (attachment)
- What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
- Display info from custom fields in all images’ HTML
- copy attachments to another post type and change attachment url
- Short of raw SQL, can I query for multiple attachment metadata that have a given array key?
- Adding meta data to an attachment post
- Regenerate missing _wp_attachment_metadata
- How to change ID of an attachment in wp_posts and its related tables correctly?
- echo image caption
- get_post_meta not working on category.php
- What are the meta fields for an attachment?
- How does WordPress treats attachments metadata in post content?
- How can i set media attachments to the author of the post or page for already existed posts with attachments
- Attachment metadata has value of ‘1’
- Create a Gallery and update Post Parent of Attachment Images
- How to append $metadata[‘sizes’] to metadata when using ‘wp_generate_attachment_metadata?
- How To Retrieve An Image Attachment’s Alt Text?
- Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
- Insert an image into a post by API
- How to update/insert custom field(post meta) data with wordpress REST API?
- Separate attachment images from post loop
- Conditional Statement – check if post has an attachment image
- Allowing post attachments without allowing to insert in text
- How do I create Comma Separated list of attached image ids?
- Can’t translate the post meta data (Date) in another language
- Display Single Attachment Image file size, uploaded date, resolution, file-name etc in Sidebar
- get_post_custom()
- Converting a simple plugin to be placed inside of functions.php
- query attachment images … if no attachments -> get attachments of parent page?
- get_attachment_id() only get id of first attached image after post update
- Mass importing json data into custom fields (postmeta)
- Get the url of the full sized attachment image using post ID?
- Custom page template to display all image attachments
- get_post_meta remains empty while looping all menu items and using the ID
- how do I set a schedule event to modify all posts’s meta value weekly or monthly?
- How to stop wp_postmeta from being called on archive and search pages?
- How can I attach hotlinked images in posts/pages within the same server?
- WordPress Image Attachment using remote image
- running function during post save and adding variable to post meta
- update_post_meta saves nothing in database when run in publish_post
- Auto delete attachments that are older than x days
- Custom post meta values reset by autosave [duplicate]
- Compare meta_query with a Regular Expression and do a less-than operation on it
- Replacing the content of an image attachment using API
- Clean up images, delete unused image sizes attached to a post type
- Editing does not change post_name
- Compare string with post id in wpdb and do stuff when match is found
- $wpdb class updating meta_value using Ajax [closed]
- How to selected which tags to print, instead of printing the whole tag list?
- query posts and split meta information into separate div’s
- Getting Different Size Of Attachment Images
- add unique string as custom-field to every post
- How do I insert a new meta key / value pair, but only if another meta key is present?
- Get images attached to a specific page
- “Cannot use import statement outside a module” JS error while adding a custom meta block?
- Gutenberg featured image checkbox – checkbox not correctly set on editing page reload
- How to properly use oneOf and anyOf in Rest Schema?
- Get the author meta adds now
- wordpress is_front_page() issue
- If ACF meta_key has meta_value
- Unable to get wp_get_attachment_url to show
- How we can get “get_post_meta” of specific user who added it
- Repeated nav bar queries failing to be cached
- Randomizing Post Links Outside of Loop – No Author or Date
- Excluding post thumbnail from the attachment.php when using wordpress gallery
- help to decipher wp metadata
- Insert Custom Field Value
- SQL query – get a featured image’s alt / alternative text
- I can not display meta value in extras.php and template-tags.php
- update_post_meta() updating nested array in Multidimensional array with empty sub-array
- How do I list taxonomies that have upcoming events in WP? Is there a way to do this without having to query posts first?
- Sorting my posts on homepage my specific value in post_meta table
- Strict comparisons problem when using boolean post meta
- Why is the actual number of thumbnail images not matching what is store in an attachments metadata?
- Check if any meta on the post has value then display content
- SQL: How to find all attachments that are not used in any posts/pages/custom_post_types
- Combine meta query and give a specific meta query a higher priority
- Get table parameter and save in meta value
- How to add/update post meta to use in query?
- gettext localization is not working
- Move Entry Meta Above Title in Archives (Genesis + Brunch Pro)
- Exclude category from DB query
- Update event post meta each day automaticaly
- Advanced Custom Field — grabbing post_meta from previous post
- Issue on Getting WP Gallery Items In cpt-single.php As Attachments
- How to create a link for wordpress meta datas?
- Fetch post meta data on POST request
- Upload unnattached image from frontend
- Image attachement management – a philosophical question
- wp_get_attachment_link() add rel attribute if the link points to direct image
- How to update post meta with xml data
- wp_postmeta store multiple values in one key [closed]
- How we insert values into database using metabox WordPress?
- How to link images of one WP site to another WP site?
- Save frontend submission form field as custom field
- Broken images after importing posts and opening in Gutenberg
- How to get WordPress to resize images for srcset?
- Define how an attached image is rendered
- Hide individual page title using checkbox in custom meta box?
- Footnotes are not copied as a block