There are two methods:
-
$attachment_meta = get_post_meta( $post->ID, '_wp_attachment_meta', true );
Will return an
array()
:$width = $attachment_meta['width'];
That
true
as 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 can I get or the intermediate size of an image with wp_get_attachment_image_src without using post meta?
- Some images not being returned with wp_get_attachment_image
- Getting meta content from get_next_post & get_previous_post
- Check whether attachment ID is associated with more than one post?
- Setting name of attachment URL
- Change default options on attachment page
- How can I hide previous_image_link() on first attachment page?
- Incomplete attachment page
- Lots of attachments is causing slow load
- How to show post attachment image
- How can I prevent the post_modified column in wp_posts from being updated?
- How to update the ‘modified_time’ of a post ONLY when content is changed?
- Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
- How to force attachment size for every post
- How do I delete element from a serialized array upon deletion of a post?
- How to get pictures of the WordPress post
- Sorting meta box values by start- and enddate and all dates in between
- How to retrieve “custom url” from image attachment in wordpress
- Use an id on a button to update_post_meta in post
- When importing posts to a new site if XML file has postmeta not setup on new server what happens?
- How to create a link for wordpress meta datas?
- Retreive tags from attached post for media on page
- Media library orphans
- Show title when inserting single images
- list of attachments: wp_get_attachment_link works, wp_get_attachment_image does not
- Fetch post meta data on POST request
- Get value from post meta array, and add it as a category
- Adding thumbnails for non-image attachments
- Multiple If else statements on Search Result Page
- Which query method to use? (edit- wpdb syntax problems)
- Using mysql queries to delete custom post types based on meta_value
- WordPress join posts with meta values of array type
- Get meta information from post parent
- Retrieve post data via WPDB class
- get_post_meta image width for lazy load
- What is the most efficient way to retrieve a group of image URL’s from different attachment ID’s of a specific crop size?
- Access Serialized Post Meta Values
- delete attachment for one post without deleting actual attachment post
- Upload unnattached image from frontend
- Write query according to post_meta
- Image attachement management – a philosophical question
- Custom Fields help
- Cache metadata for set of posts
- Does post-meta belong in header?
- wp_get_attachment_link() add rel attribute if the link points to direct image
- How to make certain content of the post noindex and no follow. not entire post?
- WordPress Attachments vs Post Meta
- How to update post meta with xml data
- greater flexibility in targeting images attached to page
- Export posts with postmeta without ID?
- Stop Attachment image names from taking top level permalink
- get_image_tag filter not working
- get_children filter with postmeta
- How to access & display images from a post without textual content ( and vice versa) according to best wordpress practices
- Why values dont shows in custom post column?
- get_post_meta of multiple posts?
- WP-API : post_meta not updated… but have another entry
- Change attachment inside the_content using filters
- get_post_custom: get image URL instead of image ID
- Counting number of identical meta keys
- Parse error thrown by get_post_meta [closed]
- How can I display my meta value in a textarea? [closed]
- delete blank space in post_meta empty [closed]
- getting image alt text via ACF plugin in WordPress [closed]
- wp_postmeta store multiple values in one key [closed]
- Auto save title as custom meta field value
- How to get all the related ids without array?
- Remove action of an external plugin after checking if custom post meta is set
- How we insert values into database using metabox WordPress?
- I am stuck between post meta function to call unique id
- How to link images of one WP site to another WP site?
- query with custom field
- How can we see which posts don’t have a featured image or it doesn’t exist anymore?
- Problem with get_post_meta
- Using Form to alter PHP variable [closed]
- Chance post id into post name
- Save frontend submission form field as custom field
- How to show wordpress post in the site based on custom field value?
- get_post_meta() returns nothing in save_post, publish_post, wp_after_insert_post
- Broken images after importing posts and opening in Gutenberg
- Image Attachments Query Not Working If Post Is Loaded Via Ajax
- wordpress query making site very slow
- How can I use an image from an external source without uploading it to the media library
- if condition from post_meta not working in save_post