I want to get wp_attachment_metadata
in my own way. I want to separate the sizes (Thumbnail, Large, Medium, Small). The meta value on database looks like this:
a:5:{s:5:"width";i:660;s:6:"height";i:320;s:4:"file";s:39:"2013/07/debut
-busana-muslim-new-yor.jpg";s:5:"sizes";a:2:{s:9:"thumbnail";a:4:{s:4:"f
ile";s:39:"debut-busana-muslim-new-yor-150x150.jpg";s:5:"width";i:150;s:
6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";}s:6:"medium";a:4:{s:
4:"file";s:39:"debut-busana-muslim-new-yor-300x145.jpg";s:5:"width";i:30
0;s:6:"height";i:145;s:9:"mime-type";s:10:"image/jpeg";}}s:10:"image_met
a";a:10:{s:8:"aperture";i:0;s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:
"caption";s:0:"";s:17:"created_timestamp";i:0;s:9:"copyright";s:0:"";s:1
2:"focal_length";i:0;s:3:"iso";i:0;s:13:"shutter_speed";i:0;s:5:"title";
s:0:"";}}
Well, I am stuck. I donât know how to separate that array. Anyone knows how to separate that array in order I can get the sizes and the URL of the images.
There are two methods:
get_post_meta()
Will return an
array()
: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.wp_get_attachment_metadata()
This function is sort of a wrapper for the above
get_post_meta()
call.In both cases,
$post
is the attachment, not the parent post to which the attachment is uploaded.