gpt4 book ai didi

php - 如何将自定义帖子类型类别分开以发布类别

转载 作者:行者123 更新时间:2023-12-04 03:14:34 24 4
gpt4 key购买 nike

我试图将特定帖子类型“公告”的类别列表与帖子类别分开。

我希望我的公告帖子类型有自己的类别列表,而不是与帖子类别列表混合

这是我的代码

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');

我们需要将其与您创建并注册的新分类进行交换,因此将其交换为:

register_taxonomy_for_object_type('announcement_type', 'announcement');

如果这对您有用,请告诉我,这里可能还有更多问题,但这可能也足够了。

关于php - 如何将自定义帖子类型类别分开以发布类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42233405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com