This is trivial, but I can't really find an answer, I've seen some hints like search in database etc., but this is madness.
Basically, I have a metabox with upload button that allows you to upload or pick existing image from Media Library, that's how I get the URL of this image:
$my_image = get_post_meta($post->ID, '_my_image_metabox', true);
Of course I do want exact size of this image to be displayed so I need to use:
wp_get_attachment_image_src($attachment_id, 'desired-size');
The question is how do I get attachment_id
of _my_image_metabox
? I've been searching literally everywhere and there are no sane answers, how is wp_get_attachment_image_src()
supposed to work if there's not a single line on getting $attachment_id
in Codex whatsoever? :)
[updated]
var_dump($my_image)
returns:
array(1) { [0]=> string(86) "http://localhost/theme/wp-content/uploads/2014/10/my_image.jpg" }
Saving the data is pretty complicated as I use my own metabox generating class, something like this: https://github.com/nyordanov/SmartMetaBox/blob/master/SmartMetaBox.php
How do I inject the proper attachment_id to my_image then? I'd add I have multiple (10) fields like this one and would like every single one to have separate, unique attachment_id.
$my_image
is just a string. Setget_post_meta
tofalse
and debug what it actually returns.