Wordpress创建新的注册类别?

时间:2017-11-22 06:39:40

标签: wordpress

我想创建新的注册组类别。我在帖子中有一个全局类别,但我创建了新插件,然后我想创建新类别。我的代码:

function movie_create_taxonomy() {
    register_taxonomy_for_object_type( 'category', 'movie' );
}
add_action( 'init', 'movie_create_taxonomy' );

然后我有一个类别的地方,我希望新的组类别只使用此插件movie。这不好,因为当我为类别I运行循环时打印所有类别但我只需要movie插件中的类别。

如何创建新的注册类别?我只找到分类法,但这并不是我想要的: register taxonomy

你有什么想法吗?

1 个答案:

答案 0 :(得分:1)

function movie_create_taxonomy() {

    /**
     * Taxonomy: Categories.
     */

    $labels = array(
        "name" => __( "Categories", "" ),
        "singular_name" => __( "Categories", "" ),
    );

    $args = array(
        "label" => __( "Categories", "" ),
        "labels" => $labels,
        "public" => true,
        "hierarchical" => true,
        "label" => "Categories",
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => array( 'slug' => 'category', 'with_front' => true, ),
        "show_admin_column" => false,
        "show_in_rest" => false,
        "rest_base" => "",
        "show_in_quick_edit" => false,
    );
    register_taxonomy( "category", array( "movie" ), $args );
}

add_action( 'init', 'movie_create_taxonomy' );