【问题标题】:WP Custom Post Type Taxonomy - Need to create CategoriesWP Custom Post Type Taxonomy - 需要创建类别
【发布时间】:2014-06-05 19:05:04
【问题描述】:

我正在尝试创建一个名为“奖励”的自定义帖子类型。在这个自定义帖子类型中,我想创建一个名为“Lighting Incentives”的类别。我创建了一个函数来注册自定义帖子类型并创建分类/类别。但是,由于某种原因,我无法注册分类/类别。分类/类别不会出现在 WP 仪表板中。此外,“激励”与“照明激励”的层次结构似乎有些混淆。这是我的代码

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();
}

【问题讨论】:

    标签: php wordpress custom-post-type taxonomy


    【解决方案1】:

    您应该使用小写字母作为自定义帖子类型的名称。改变这个

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

    到这里

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

    编辑

    你应该只刷新你的永久链接一次

    【讨论】:

      猜你喜欢
      • 2014-07-05
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 2021-03-12
      • 2022-12-02
      • 1970-01-01
      • 2022-12-01
      • 1970-01-01
      相关资源
      最近更新 更多