【问题标题】:Adding custom taxonomies to a custom post, how?将自定义分类法添加到自定义帖子,如何?
【发布时间】:2012-04-10 12:36:08
【问题描述】:

我在向我的自定义帖子添加自定义分类时遇到了一些问题。我已经创建了这样的自定义帖子:

add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'profiel_pagina',
    array(
        'labels' => array(
            'name' => __( 'Profiel pagina' ),
            'singular_name' => __( 'Profiel pagina' )
        ),
    'public' => true,
    'has_archive' => true,
    'supports'   => array('title', 'editor', 'thumbnail')
    )
);

还有像这样的自定义分类法:

function create_my_taxonomies() {
register_taxonomy('vakgebied', 'post', array(
'hierarchical' => false, 'label' => 'Vakgebied',
'query_var' => true, 'rewrite' => true));
}register_taxonomy('specialisatie', 'post', array(
'hierarchical' => false, 'label' => 'Specialisatie',
'query_var' => true, 'rewrite' => true));
 }
add_action('init', 'create_my_taxonomies', 0);

这一切都很好,但我怎样才能将这两者联系起来呢?使用 'taxonomies' => array('post-tag') 不起作用。根据法典,在添加自定义分类时也使用“post”不是正确的方法,但我应该怎么做?

非常感谢任何帮助。

【问题讨论】:

    标签: wordpress custom-post-type custom-taxonomy


    【解决方案1】:

    您目前正在将您的分类添加到 post 内容类型。您想将它们添加到profiel_pagina,以便使用register_taxonomy('vakgebied', 'profiel_pagina', array(...));

    【讨论】:

    • 非常感谢,这就行了!其实很简单,如果你知道怎么做的话;-)
    猜你喜欢
    • 1970-01-01
    • 2012-07-29
    • 2014-08-29
    • 2013-08-04
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多