Custom category for custom post type

一个人想着一个人 提交于 2019-12-11 20:36:37

问题


I added a custom post type to my wordpress theme. I related with category taxonomy, I can relate with the same categories as the posts. What I need is a custom category for my custom post type.

Eg: "book" for post type and book-category/fictional

I need it to be different than post categories. Is this possible?


回答1:


Yes sir it is possible!

http://codex.wordpress.org/Taxonomies

In a nutshell:

function register_book_genre_taxonomy() {
    register_taxonomy(
        'book_genre',
        'book',
        array(
            'label' => __( 'Genre' ),
            'rewrite' => array( 'slug' => 'genre' )
        )
    );
}

add_action( 'init', 'register_book_genre_taxonomy' );


来源:https://stackoverflow.com/questions/25127594/custom-category-for-custom-post-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!