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 get image title/alt attribute?
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- How can I get the post ID from a WP_Query loop?
- How to edit a post meta data in a Gutenberg Block?
- How to add a class to the attachment images
- How to paginate attachments in a secondary query as gallery?
- How to add classes to images based on their categories?
- How can I hide media library images from general users?
- How to delete outdated, wrongly sized images in _wp_attachment_metadata?
- How to update/delete array in post meta value?
- Add multiple images to a page sidebar
- How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?
- Add custom field to image editor
- Why am I getting an infinite loop with have_posts?
- How to change _wp_attachment_metadata specific value in SQL?
- Count all images of a certain post type
- Applying class to links around self hosted images embedded to posts/pages
- How to store post meta in an array?
- Stopping WordPress from Auto Generating Image Files for Sizes
- Save attachment custom fields on front end
- update_post_meta() not working when used with WordPress action
- Pulling Post Image Attachments in WordPress 3.9
- Get posts by meta value with date
- Use Timber/Twig to pull an image by image ID [closed]
- Link Featured Thumb to Attachment Page, If Possible
- Importing media medium setting image gallery / image attachments
- Get updated post meta on save_post action?
- Image still linked as attachment to page even though it has been deleted
- Delete post meta conditionally after save post
- wp_query for displaying attachments with a tag
- Job of meta_key meta_value fields in database tables
- How to store Gutenberg ColourPicker RGBA as metadata
- Attachment 0×0 size error [closed]
- Query 2 meta key values and a category
- trying to do if post meta !=0
- Add a new data attribute in tag
- how to build (custom) stats for post views, per month
- get_post_meta pagination
- Removing Post Meta from Category Pages?
- Hey, I want the second options. get_post_meta()
- Update post meta in woocommerce order frontend
- Display attachment resolution size
- How to display post view count by date, week and month?
- How can I filter posts when the meta_value is a serialize object?
- Get User Post if Private
- Unknown characters added to meta data values
- Get post attached image to display in admin dashboard
- Get attachments for posts that belongs to a specific category
- wp_upload_bits Upload Specific Sizes Only
- get_post_meta($post->ID) returns empty string when in preview mode of custom post type
- need to add add user names to the post for later retrieval or removal
- get_permalink vs the_permalink
- wp get attachment image always gives me thumbnail
- Updating my Post when expiry date is past
- Get title of post image is attached to
- How to display sql query fired by posts_where
- Unfiltered html with update_post_meta
- get meta value from page query
- Upload attachment from external site
- Remove “%” from strings in serialized arrays in wp_postmeta
- Front end file upload returning wrong attachment url
- Use full size images in a specific gallery
- How to get custom image field of specific post id
- WP_Query: attachment image in “full” size?
- How to query and update one colum in postmeta table?
- How to remove date from showing in meta description
- update post meta value with other post meta value
- Check For get_post_meta on Author Archive Page
- Negative meta_query if storing multiple post_meta values with shared meta_key
- What format is this and how to get value “lal” and “pila” from it
- Frontend query and does not need to log in [closed]
- Get data from custom table and update relative post_meta based on meta_key
- How to save a meta_value as a numeric value after I retrieve it via update_post_meta?
- Get attachment URL from attachment Link in WordPress
- Data not displaying in text field
- Delete custom post type metadata without deleting the post in admin area
- Proper Way to Sanitize Meta Input
- update_post_meta returning false when called during init
- Incomplete attachment page
- How to retrieve “custom url” from image attachment in wordpress
- list of attachments: wp_get_attachment_link works, wp_get_attachment_image does not
- What is the most efficient way to retrieve a group of image URL’s from different attachment ID’s of a specific crop size?
- Cache metadata for set of posts
- How to access & display images from a post without textual content ( and vice versa) according to best wordpress practices
- Problem with get_post_meta