我编写了一个类,用于在选项表中存储分类术语的元数据,使用它非常简单,例如:
//include the main class file
require_once("Tax-meta-class/Tax-meta-class.php");
// configure taxonomy custom fields
$config = array(
\'id\' => \'demo_tax_meta_box\', // meta box id, unique per meta box
\'title\' => \'Demo Meta Box\', // meta box title
\'pages\' => array(\'menus\'), // taxonomy name, accept categories, post_tag and custom taxonomies
\'context\' => \'normal\', // where the meta box appear: normal (default), advanced, side; optional
\'fields\' => array(), // list of meta fields (can be added by field arrays)
\'local_images\' => false, // Use local or hosted images (meta box images for add/remove)
\'use_with_theme\' => false //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
);
// Initiate your taxonomy custom fields
$my_meta = new Tax_Meta_Class($config);
// Add fields
//text field
$my_meta->addText(\'text_field_id\',array(\'name\'=> \'My tax Text \'));
//textarea field
$my_meta->addTextarea(\'textarea_field_id\',array(\'name\'=> \'My tax Textarea \'));
//Image field
$my_meta->addImage(\'image_field_id\',array(\'name\'=> \'My tax Image \'));
//Finish Taxonomy Extra fields Deceleration
$my_meta->Finish();
这将添加文本字段、文本区域字段和图像字段。获取存储的数据也非常简单:
$saved_data = get_tax_meta($term_id,\'text_field_id\');
echo $saved_data;
当前该类支持:
输入文本区域单选按钮复选框选择下拉列表文件上传图像上传所见即所得编辑器日期选择器时间选择器颜色选择器分类列表下拉列表阅读更多信息请看:WordPress taxonomies extra fields the easy way