Remove categories taxonomy from custom post type

I've got a custom post type called "Resources".How I've defined the taxonomy:register_taxonomy(�

I've got a custom post type called "Resources".

How I've defined the taxonomy:

register_taxonomy(  
    'resource',  // the name of the taxonomy
    'resources', // post type name
    array(  
        'hierarchical' => true,  
        //'label' => 'Resources',  // display name
        'query_var' => true,
        'rewrite' => array(
            'slug' => 'resources', // This controls the base slug that will display before each term
            'with_front' => false // Don't display the category base before 
        )
    )  
);  

How I've registered the post type:

register_post_type(
            'resources',
            tp_build_post_args(
                'resources', 'Resource', 'Resources',
                array(
                    'menu_icon'     => 'dashicons-welcome-write-blog',
                    'menu_position' => 20,
                    'has_archive'   => true,
                    'public'      => true,
                    'supports' => array('editor', 'title','author','thumbnail', 'revisions'),
                    'taxonomies' => array('post_tag', 'type', 'sector')
                )
            )
        );

As you can see, I do not have the category option selected in 'taxonomies' => array('post_tag', 'type', 'sector'), but it is appearing as an option in the admin:

Why is this?

I've got a custom post type called "Resources".

How I've defined the taxonomy:

register_taxonomy(  
    'resource',  // the name of the taxonomy
    'resources', // post type name
    array(  
        'hierarchical' => true,  
        //'label' => 'Resources',  // display name
        'query_var' => true,
        'rewrite' => array(
            'slug' => 'resources', // This controls the base slug that will display before each term
            'with_front' => false // Don't display the category base before 
        )
    )  
);  

How I've registered the post type:

register_post_type(
            'resources',
            tp_build_post_args(
                'resources', 'Resource', 'Resources',
                array(
                    'menu_icon'     => 'dashicons-welcome-write-blog',
                    'menu_position' => 20,
                    'has_archive'   => true,
                    'public'      => true,
                    'supports' => array('editor', 'title','author','thumbnail', 'revisions'),
                    'taxonomies' => array('post_tag', 'type', 'sector')
                )
            )
        );

As you can see, I do not have the category option selected in 'taxonomies' => array('post_tag', 'type', 'sector'), but it is appearing as an option in the admin:

Why is this?

Share Improve this question asked Aug 21, 2019 at 13:48 FreddyFreddy 1771 silver badge12 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 3

First, I believe that "Categories" is actually for the custom taxonomy resource and not the standard category taxonomy. But in the menu, it's labeled Categories because you didn't set a custom label for the resource taxonomy (because the label is commented out and defaults to Categories):

register_taxonomy(
    'resource',  // the name of the taxonomy
    'resources', // post type name
    array(
        'hierarchical' => true,
        //'label' => 'Resources',  // display name <- this
        ...
    )
);

Secondly, the resource taxonomy is actually assigned to the resources post type, despite the taxonomy is not in the list of the post type's taxonomies property:

register_taxonomy(
    'resource',  // the name of the taxonomy
    'resources', // post type name <- here, the taxonomy will be assigned to this post type
    array( ... )
);

If you don't actually want the resource taxonomy to be assigned to the resources post type, then either set the post type to null or whatever the proper post type is:

register_taxonomy(
    'resource',  // the name of the taxonomy
    null,        // set to null, which means don't assign to `resources` or any post types..
    array( ... )
);

Alternatively, you can use unregister_taxonomy_for_object_type() to un-assign the taxonomy from a post type:

// Call after the post type and taxonomy are both registered.
unregister_taxonomy_for_object_type( 'resource', 'resources' );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745227374a4617524.html

相关推荐

  • Remove categories taxonomy from custom post type

    I've got a custom post type called "Resources".How I've defined the taxonomy:register_taxonomy(�

    5小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信