我已经制定了自定义分类法,用于几种不同的帖子类型:
<?php
add_action(\'init\', function() {
register_post_type(\'intranet-categories\', [
\'labels\' => [
\'name\' => \'Kategorier\',
\'singular_name\' => \'Kategorier\',
\'menu_name\' => \'Kategorier\',
\'name_admin_bar\' => \'Kategorier\',
\'add_new\' => \'Legg til ny\',
\'add_new_item\' => \'Ny Kategori\',
\'new_item\' => \'Ny Kategori\',
\'edit_item\' => \'Rediger Kategori\',
\'view_item\' => \'Vis Kategori\',
\'all_items\' => \'Alle Kategorier\',
\'search_items\' => \'Søk\',
\'parent_item_colon\' => \'Forelder\',
\'not_found\' => \'Fant ingen Kategori.\',
\'not_found_in_trash\' => \'Fant ingen Kategori i søppelkassen.\',
],
\'description\' => \'Kategori\',
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => [\'slug\' => \'intranet-categories\'],
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => null,
\'menu_icon\' => \'dashicons-editor-ol\',
\'supports\' => [\'title\', \'editor\', \'excerpt\', \'thumbnail\'],
\'capability_type\' => \'custom_post_type\',
\'capabilities\' => [\'create_posts\' => false],
]);
register_taxonomy(\'department\', [\'intranet-categories\', \'intranet-post\'], [
\'labels\' => [
\'name\' => \'Avdeling\',
\'singular_name\' => \'Avdeling\',
\'search_items\' => \'Søk\',
\'all_items\' => \'Alle avdelinger\',
\'parent_item\' => \'Forelder\',
\'parent_item_colon\' => \'Forelder\',
\'edit_item\' => \'Rediger avdeling\',
\'update_item\' => \'Oppdater avdeling\',
\'add_new_item\' => \'Opprett avdeling\',
\'new_item_name\' => \'Ny avdeling\',
\'menu_name\' => \'Avdelinger\',
],
\'hierarchical\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => [\'slug\' => \'avdeling\'],
]);
register_taxonomy(\'region\', [\'intranet-categories\', \'intranet-post\'], [
\'labels\' => [
\'name\' => \'Region\',
\'singular_name\' => \'Region\',
\'search_items\' => \'Søk\',
\'all_items\' => \'Alle region\',
\'parent_item\' => \'Forelder\',
\'parent_item_colon\' => \'Forelder\',
\'edit_item\' => \'Rediger Region\',
\'update_item\' => \'Oppdater Region\',
\'add_new_item\' => \'Opprett Region\',
\'new_item_name\' => \'Ny Region\',
\'menu_name\' => \'Regioner\',
],
\'hierarchical\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => [\'slug\' => \'avdeling\'],
]);
register_taxonomy(\'industry\', [\'intranet-categories\', \'intranet-post\'], [
\'labels\' => [
\'name\' => \'Bransje\',
\'singular_name\' => \'Bransje\',
\'search_items\' => \'Søk\',
\'all_items\' => \'Alle bransjer\',
\'parent_item\' => \'Forelder\',
\'parent_item_colon\' => \'Forelder\',
\'edit_item\' => \'Rediger bransje\',
\'update_item\' => \'Oppdater bransje\',
\'add_new_item\' => \'Opprett bransje\',
\'new_item_name\' => \'Ny bransje\',
\'menu_name\' => \'Bransjer\',
],
\'hierarchical\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => [\'slug\' => \'bransje\'],
]
);
register_taxonomy(\'role\', [\'intranet-categories\', \'intranet-post\'], [
\'labels\' => [
\'name\' => \'Rolle\',
\'singular_name\' => \'Rolle\',
\'search_items\' => \'Søk\',
\'all_items\' => \'Alle roller\',
\'parent_item\' => \'Forelder\',
\'parent_item_colon\' => \'Forelder\',
\'edit_item\' => \'Rediger rolle\',
\'update_item\' => \'Oppdater rolle\',
\'add_new_item\' => \'Opprett rolle\',
\'new_item_name\' => \'Ny rolle\',
\'menu_name\' => \'Roller\',
],
\'hierarchical\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => [\'slug\' => \'rolle\'],
]
);
register_taxonomy(\'company\', [\'intranet-categories\', \'intranet-post\'], [
\'labels\' => [
\'name\' => \'Selskap\',
\'singular_name\' => \'Selskap\',
\'search_items\' => \'Søk\',
\'all_items\' => \'Alle selskaper\',
\'parent_item\' => \'Forelder\',
\'parent_item_colon\' => \'Forelder\',
\'edit_item\' => \'Rediger selskap\',
\'update_item\' => \'Oppdater selskap\',
\'add_new_item\' => \'Opprett selskap\',
\'new_item_name\' => \'Ny selskap\',
\'menu_name\' => \'Selskaper\',
],
\'hierarchical\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => [\'slug\' => \'selskap\'],
]
);
});
我想做的是在管理菜单中隐藏创建的自定义分类法
intranet-post
键入,并且仅在的“管理”菜单中可见
intranet-categories
, 因为我只想编辑这些自定义分类法,并从
intranet-categories
岗位类型。我试过这样做:
function remove_taxonomy_submenu_pages() {
$categories = get_object_taxonomies(\'intranet-categories\');
foreach($categories as $category) {
remove_menu_page( \'edit.php\', \'edit-tags.php?taxonomy=\' . $category . \'&post_type=intranet-post\' );
}
}
add_action( \'admin_menu\', \'remove_taxonomy_submenu_pages\', 20);
但是,这不起作用,正确的方法是什么?