我試圖從帖子類別中爲特定帖子類型「公告」區分類別列表。如何將自定義帖子類型分類到帖子類別
我希望我公佈職位類型有其自己的類別列表,而不是與職位類別列表中混用
這裏是我的代碼
function announcement_post_types() {
register_post_type(
'announcement',
array(
'labels' => array(
'name' => __('Announcements'),
'singular_name' => __('announcement'),
'menu_name' => __('Announcements'),
'all_items' => __('All Announcements'),
'view_item' => __('View Announcement'),
'add_new_item' => __('New Announcement'),
'add_new' => __('New Announcement'),
'edit_item' => __('Edit Announcements'),
'update_item' => __('Update'),
'search_items' => __('Search'),
'not_found' => __('Not Found'),
'not_found_in_trash' => __('Not Found in Trash'),
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => 'announcement'),
'menu_icon' => 'dashicons-admin-page',
'supports' => array('title', 'editor', 'custom-fields')
)
);
register_taxonomy(
'announcement_type',
'announcement', // this is the custom post type(s) I want to use this taxonomy for
array(
'hierarchical' => false,
'label' => 'News Types',
'query_var' => true,
'rewrite' => true
)
);
register_taxonomy_for_object_type('category', 'announcement');
}
add_action('init', 'announcement_post_types');
感謝兄弟們,我只是更新了我的代碼,它現在適用於我,現在我刪除了register_taxonomy_for_object_type('category','announcement'); –
很高興我能幫忙! –