我需要为 2 种不同的帖子类型注册分类法,并且我尝试使用以下代码来实现这一点:
功能 add_custom_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels_adp = array(
'name' => _x( 'Apples', 'taxonomy general name' ),
'singular_name' => _x( 'Apple', 'taxonomy singular name' ),
'search_items' => __( 'Search Apples' ),
'all_items' => __( 'All Apples' ),
'parent_item' => __( 'Parent Apples' ),
'parent_item_colon' => __( 'Parent Apples:' ),
'edit_item' => __( 'Edit Apples' ),
'update_item' => __( 'Update Apples' ),
'add_new_item' => __( 'Add New Apples' ),
'new_item_name' => __( 'New Genre Apples' ),
'menu_name' => __( 'Apples' )
);
$args_adp = array(
'hierarchical' => true,
'labels' => $labels_adp,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'apple' )
);
$labels_cw = array(
'name' => _x( 'Genres', 'taxonomy general name' ),
'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
'search_items' => __( 'Search Genres' ),
'all_items' => __( 'All Genres' ),
'parent_item' => __( 'Parent Genre' ),
'parent_item_colon' => __( 'Parent Genre:' ),
'edit_item' => __( 'Edit Genre' ),
'update_item' => __( 'Update Genre' ),
'add_new_item' => __( 'Add New Genre' ),
'new_item_name' => __( 'New Genre Name' ),
'menu_name' => __( 'Genre' )
);
$args_cw = array(
'hierarchical' => true,
'labels' => $labels_cw,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' )
);
register_taxonomy( 'apple', array( 'adp' ), $args_adp );
register_taxonomy( 'genre', array( 'cw' ), $args_cw );
}
add_action( 'init', 'add_custom_taxonomies', 0 );
不幸的是,它根本不起作用,只呈现一种分类法一种帖子类型。不知道为什么。