我在functions.php
使用以下代码:
<?php
add_action( \'init\', function() {
$labels = array(
\'name\' => _x( \'Resource Centers\', \'taxonomy general name\', \'textdomain\' ),
\'singular_name\' => _x( \'Resource Center\', \'taxonomy singular name\', \'textdomain\' ),
\'search_items\' => __( \'Search Resource Centers\', \'textdomain\' ),
\'all_items\' => __( \'All Resource Centers\', \'textdomain\' ),
\'parent_item\' => __( \'Parent Resource Center\', \'textdomain\' ),
\'parent_item_colon\' => __( \'Parent Resource Center:\', \'textdomain\' ),
\'edit_item\' => __( \'Edit Resource Center\', \'textdomain\' ),
\'update_item\' => __( \'Update Resource Center\', \'textdomain\' ),
\'add_new_item\' => __( \'Add New Resource Center\', \'textdomain\' ),
\'new_item_name\' => __( \'New Resource Center Name\', \'textdomain\' ),
\'menu_name\' => __( \'Resource Center\', \'textdomain\' ),
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'public\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'resource-center\' ),
);
register_taxonomy( \'resource-center\', array( \'post\' ), $args );
$labels = array(
\'name\' => _x( \'Blog Categories\', \'taxonomy general name\', \'textdomain\' ),
\'singular_name\' => _x( \'Blog\', \'taxonomy singular name\', \'textdomain\' ),
\'search_items\' => __( \'Search Blog Categories\', \'textdomain\' ),
\'all_items\' => __( \'All Blog Categories\', \'textdomain\' ),
\'parent_item\' => __( \'Parent Blog Category\', \'textdomain\' ),
\'parent_item_colon\' => __( \'Parent Blog Category:\', \'textdomain\' ),
\'edit_item\' => __( \'Edit Blog Category\', \'textdomain\' ),
\'update_item\' => __( \'Update Blog Category\', \'textdomain\' ),
\'add_new_item\' => __( \'Add New Blog Category\', \'textdomain\' ),
\'new_item_name\' => __( \'New Blog Category Name\', \'textdomain\' ),
\'menu_name\' => __( \'Blog Categories\', \'textdomain\' ),
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'public\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'blogs\', \'with_front\' => true ),
);
register_taxonomy( \'blog\', array( \'post\' ), $args );
$labels = array(
\'name\' => _x( \'Marketing Tags\', \'taxonomy general name\', \'textdomain\' ),
\'singular_name\' => _x( \'Marketing Tag\', \'taxonomy singular name\', \'textdomain\' ),
\'search_items\' => __( \'Search Marketing Tags\', \'textdomain\' ),
\'all_items\' => __( \'All Marketing Tags\', \'textdomain\' ),
\'parent_item\' => __( \'Parent Marketing Tag\', \'textdomain\' ),
\'parent_item_colon\' => __( \'Parent Marketing Tag:\', \'textdomain\' ),
\'edit_item\' => __( \'Edit Marketing Tag\', \'textdomain\' ),
\'update_item\' => __( \'Update Marketing Tag\', \'textdomain\' ),
\'add_new_item\' => __( \'Add New Marketing Tag\', \'textdomain\' ),
\'new_item_name\' => __( \'New Marketing Tag Name\', \'textdomain\' ),
\'menu_name\' => __( \'Marketing Tag\', \'textdomain\' ),
);
$args = array(
\'hierarchical\' => false,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'public\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'marketing-tag\' ),
);
register_taxonomy( \'marketing-tag\', array( \'post\' ), $args );
$labels = array(
\'name\' => _x( \'Video Playlists\', \'taxonomy general name\', \'textdomain\' ),
\'singular_name\' => _x( \'Video Playlist\', \'taxonomy singular name\', \'textdomain\' ),
\'search_items\' => __( \'Search Video Playlists\', \'textdomain\' ),
\'all_items\' => __( \'All Video Playlists\', \'textdomain\' ),
\'parent_item\' => __( \'Parent Video Playlist\', \'textdomain\' ),
\'parent_item_colon\' => __( \'Parent Video Playlist:\', \'textdomain\' ),
\'edit_item\' => __( \'Edit Video Playlist\', \'textdomain\' ),
\'update_item\' => __( \'Update Video Playlist\', \'textdomain\' ),
\'add_new_item\' => __( \'Add New Video Playlist\', \'textdomain\' ),
\'new_item_name\' => __( \'New Video Playlist Name\', \'textdomain\' ),
\'menu_name\' => __( \'Video Playlist\', \'textdomain\' ),
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'public\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'video-playlist\' ),
);
register_taxonomy( \'video-playlist\', array( \'post\' ), $args );
flush_rewrite_rules(true);
});
据我所知,它们都是正确创建的,并设置为公共,在菜单/ui中可见。它们在编辑帖子或通过管理员URL直接访问时都能正常工作,例如:
/wp-admin/edit-tags.php?taxonomy=blog
/wp-admin/edit-tags.php?taxonomy=marketing-tag
/wp-admin/edit-tags.php?taxonomy=video-playlist
但是,只有资源中心分类法显示在“管理”菜单的“帖子”下。其他人失踪:
知道我的一些自定义分类法为什么没有显示在菜单中吗?虽然听起来很傻,但他们总是出现,不知怎么的,他们就消失了。