-
Notifications
You must be signed in to change notification settings - Fork 88
Image field
bainternet edited this page Jan 17, 2012
·
5 revisions
#Image field
To add an Image field to your metabox simply use the addImage
method of the metabox object:
$my_meta = new AT_Meta_Box($config);
$my_meta->addImage('image_field_id',array('name'=> 'My Image '));
- ID : field id (string)
- args: (mixed|array)
-
'name' => field name/label, (string) optional
-
'desc' => field description, (string) optional
-
- reapeater: When adding this field to a repeater block set to true (default false)
The image field data is saved as an array of image url as src
for quick access, and attachment id as id
so to simlpy display the image you can use:
$saved_data = get_post_meta($post->ID,'image_field_id',true);
echo '<img src="'.$saved_data['src'].'">';
to get the attachment id of the image use:
$saved_data = get_post_meta($post->ID,'image_field_id',true);
$attachment_id = $saved_data['id'];