// 分类添加字段
function ems_add_category_field(){
echo '
Tel
The telephone.
echo '
URL
The URL.
}
add_action('category_add_form_fields','ems_add_category_field',10,2);
// 分类编辑字段
function ems_edit_category_field($tag){
echo '
Tel'.$tag->name.' on the phone.
';echo '
URL'.$tag->name.' on the URL.
';}
add_action('category_edit_form_fields','ems_edit_category_field',10,2);
// 保存数据
function ems_taxonomy_metadate($term_id){
if(isset($_POST['cat-tel']) && isset($_POST['cat-url'])){
//判断权限--可改
if(!current_user_can('manage_categories')){
return $term_id;
}
// 电话
$tel_key = 'cat-tel-'.$term_id; // key 选项名为 cat-tel-1 类型
$tel_value = $_POST['cat-tel']; // value
// url
$url_key = 'cat-url-'.$term_id;
$url_value = $_POST['cat-url'];
// 更新选项值
update_option( $tel_key, $tel_value );
update_option( $url_key, $url_value );
}
}
// 虽然要两个钩子,但是我们可以两个钩子使用同一个函数
add_action('created_category','ems_taxonomy_metadate',10,1);
add_action('edited_category','ems_taxonomy_metadate',10,1);
?>