/ Published in: Other
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//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; }