Wp classification html, wordpress classification field is expanded to add classification type to classification

// add field to category

function add_taxonomy_field(){

$type = ['article' => 'article', 'product' => 'product', 'case' => 'case'];

$html = '

Types of';

foreach($type as $key => $val) {

$html .= '' . $val;

}

$html .= '

';

echo $html;

}

add_action('category_add_form_fields','add_taxonomy_field',10,2);

// Category edit field

function edit_taxonomy_field( $tag ){

$value = get_option('tag-type-'.$tag->term_id);

$type = ['article' => 'article', 'product' => 'product', 'case' => 'case'];

$html = '

Types of';

foreach($type as $key => $val) {

if ( $value == $key ) {

$html .= '' . $val;

} else {

$html .= '' . $val;

}

}

$html .= '

';

echo $html;

}

add_action('category_edit_form_fields','edit_taxonomy_field',10,2);

// save data

function save_taxonomy_field( $term_id ){

if( isset($_POST['tag-type']) ){

//Judgment permission -- can be changed

if(!current_user_can('manage_categories')){

return $term_id;

}

$tag_type_key = 'tag-type-'.$term_id;

$tag_type_value = $_POST['tag-type'];

// 更新选项值

update_option( $tag_type_key, $tag_type_value );

}

}

function taxonomy_setup() {

add_action('created_category','save_taxonomy_field',10,1);

add_action('edited_category','save_taxonomy_field',10,1);

}

add_action( 'admin_init', 'taxonomy_setup' );

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324066143&siteId=291194637