dtzhfb4869 2017-02-14 18:15
浏览 52

如何将自定义帖子类型类别与帖子类别分开

I'm trying to separate the category lists for a specific post type "announcement" from the post categories.

I want my announcement post type to have its own category list and not mix with the post category list

Here's my code

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');
  • 写回答

2条回答 默认 最新

  • douba9020 2017-02-14 18:25
    关注

    If this code is working, this is what links the regular categories to the announcement post type:

    register_taxonomy_for_object_type('category', 'announcement');
    

    We need to exchange it with the new taxonomy you created and registered, so exchange it with this:

    register_taxonomy_for_object_type('announcement_type', 'announcement');
    

    Let me know if this did the trick for you, there might be more issues here, but this might also be enough.

    评论

报告相同问题?

悬赏问题

  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?