Posted By

athanassiadis on 11/24/10


Tagged

image textmate wordpress functions attachment wp meta


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

qubestream


Add a custom field to an attachment in wordpress


 / Published in: Other
 

  1. //Add a custom field to an attachment in wordpress
  2. add_filter("attachment_fields_to_edit","sh_attachment_fields_to_edit",null,2);
  3. add_filter("attachment_fields_to_save","sh_attachment_fields_to_save",null,2);
  4.  
  5. add_filter("attachment_fields_to_edit","my_image_attachment_fields_to_edit",null,2);
  6. add_filter("attachment_fields_to_save","my_image_attachment_fields_to_save",null,2);
  7. function my_image_attachment_fields_to_edit($form_fields,$post){
  8. $form_fields["custom6"]["label"]=__("Custom Field with Helpful Text");
  9. $form_fields["custom6"]["value"]=get_post_meta($post->ID,"_custom6",true);
  10. $form_fields["custom6"]["helps"]="Put helpful text here.";
  11. return $form_fields;
  12. }
  13. function my_image_attachment_fields_to_save($post,$attachment){
  14. if(isset($attachment['custom6'])){
  15. update_post_meta($post['ID'],'_custom6',$attachment['custom6']);
  16. }
  17. return $post;
  18. }

Report this snippet  

You need to login to post a comment.