在wordpress中向附件添加自定义字段
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在wordpress中向附件添加自定义字段相关的知识,希望对你有一定的参考价值。
//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; }
以上是关于在wordpress中向附件添加自定义字段的主要内容,如果未能解决你的问题,请参考以下文章