简体   繁体   English

WP自定义帖子类型分类法-需要创建类别

[英]WP Custom Post Type Taxonomy - Need to create Categories

I am trying to create a custom post type called "Incentives". 我正在尝试创建一个名为“ Incentives”的自定义帖子类型。 Within this custom post type, I would like to create a category titled "Lighting Incentives". 在此自定义帖子类型中,我想创建一个标题为“ Lighting Incentives”的类别。 I have created a function to register the custom post type and create the taxonomy/category. 我创建了一个函数来注册自定义帖子类型并创建分类法/类别。 However, for some reason I am unable to register the taxonomy/category. 但是,由于某种原因,我无法注册分类法/类别。 The taxonomy/category does not appear in the WP dashboard. 分类/类别未出现在WP仪表板中。 Also, the hierarchy of "Incentives" vs "Lighting Incentives" seems a bit mixed up. 此外,“激励”与“照明激励”的层次结构似乎有些混淆。 Here is my code 这是我的代码

add_action('init', 'incentive_register');

function incentive_register() {

    $labels = array(
        'name' => _x('Lighting Incentives', 'post type general name'),
        'singular_name' => _x('Lighting Incentive', 'post type singular name'),
        'add_new' => _x('Add New', 'Lighting Incentive'),
        'add_new_item' => __('Add New Lighting Incentive'),
        'edit_item' => __('Edit Lighting Incentive'),
        'new_item' => __('New Lighting Incentive'),
        'view_item' => __('View Incentive'),
        'search_items' => __('Search Incentives'),
        'not_found' =>  __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
        'rewrite' => true,
        'capability_type' => 'post',
        'has_archive' => 'lighting-incentives',
        'menu_position' => null,
        'parent_item' => 'Incentives',
        'supports' => array('title','editor','thumbnail','excerpt','custom-fields','post-formats')
      ); 

    register_post_type( 'Incentive' , $args );
    register_taxonomy_for_object_type('category','Incentive');

        flush_rewrite_rules();
}

You should use lowercase for the name of your custom post type. 您应该使用小写字母作为自定义帖子类型的名称。 Change this 改变这个

register_post_type( 'Incentive' , $args );
register_taxonomy_for_object_type('category','Incentive');

to this 对此

register_post_type( 'incentive' , $args );
register_taxonomy_for_object_type('category','incentive');

EDIT 编辑

You should flush your permalinks only once 您应该只刷新一次永久链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM