【问题标题】:Category for only one CPT只有一个 CPT 的类别
【发布时间】:2015-07-10 19:52:21
【问题描述】:

我创建了 CPT 并添加了一个分类类别。 问题是来自 CPT 的那些类别也出现在我的博客中。 我想在我的博客中有不同的类别,在我的 CPT 作品集中有不同的类别。

这是我当前的代码 add_action('init', 'create_post_type'); 函数 create_post_type() {

    register_post_type( 'portfolio',
        array(
            'labels' => array(
                'label' => 'portfolio',
                'name' => __( 'Portfolio' ),
                'singular_name' => __( 'portfolio' )
            ),
        'public' => true,
        'has_archive' => true,
        'taxonomies' => array('category','post_tag'),
        'supports' => array( 'title', 'comments', 'excerpt', 'custom-fields', 'thumbnail' )
        )
    );
};

【问题讨论】:

    标签: wordpress categories custom-post-type taxonomy


    【解决方案1】:

    引用codex

    “即使您在创建帖子类型时注册了分类,您 仍然必须使用显式注册和定义分类法 register_taxonomy().

    基本上,您正在为您的投资组合 CPT 创建一个名为 category 的新分类。这将不包括帖子的默认类别分类。

    【讨论】:

      猜你喜欢
      • 2015-04-09
      • 1970-01-01
      • 2022-06-29
      • 1970-01-01
      • 2017-12-27
      • 2021-08-25
      • 1970-01-01
      • 2016-03-27
      • 1970-01-01
      相关资源
      最近更新 更多