Return to Snippet

Revision: 36631
at November 24, 2010 07:27 by athanassiadis


Initial Code
//Add a custom field to an attachment in wordpress
add_filter("attachment_fields_to_edit","sh_attachment_fields_to_edit",null,2);
add_filter("attachment_fields_to_save","sh_attachment_fields_to_save",null,2);

add_filter("attachment_fields_to_edit","my_image_attachment_fields_to_edit",null,2);
add_filter("attachment_fields_to_save","my_image_attachment_fields_to_save",null,2);
function my_image_attachment_fields_to_edit($form_fields,$post){
$form_fields["custom6"]["label"]=__("Custom Field with Helpful Text");
$form_fields["custom6"]["value"]=get_post_meta($post->ID,"_custom6",true);
$form_fields["custom6"]["helps"]="Put helpful text here.";
return $form_fields;
}
function my_image_attachment_fields_to_save($post,$attachment){
if(isset($attachment['custom6'])){
update_post_meta($post['ID'],'_custom6',$attachment['custom6']);
}
return $post;
}

Initial URL

                                

Initial Description

                                

Initial Title
Add a custom field to an attachment in wordpress

Initial Tags
image, textmate, wordpress

Initial Language
Other