0

我是主题开发人员,我想将“方式”等自定义分类注册到 learnpress 插件的帖子类型之一(我知道 learnpress 插件将“ lp_course ”注册为帖子类型)

我想与“ lp_press ”和“ post ”帖子类型共享“方式分类” !

这是我注册分类的代码:

// Register Custom Taxonomy
function custom_taxonomy() {

    $labels = array(
        'name'                       => _x( 'ways', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'way', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Taxonomy', 'text_domain' ),
        'all_items'                  => __( 'All Items', 'text_domain' ),
        'parent_item'                => __( 'Parent Item', 'text_domain' ),
        'parent_item_colon'          => __( 'Parent Item:', 'text_domain' ),
        'new_item_name'              => __( 'New Item Name', 'text_domain' ),
        'add_new_item'               => __( 'Add New Item', 'text_domain' ),
        'edit_item'                  => __( 'Edit Item', 'text_domain' ),
        'update_item'                => __( 'Update Item', 'text_domain' ),
        'view_item'                  => __( 'View Item', 'text_domain' ),
        'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
        'add_or_remove_items'        => __( 'Add or remove items', 'text_domain' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'text_domain' ),
        'popular_items'              => __( 'Popular Items', 'text_domain' ),
        'search_items'               => __( 'Search Items', 'text_domain' ),
        'not_found'                  => __( 'Not Found', 'text_domain' ),
        'no_terms'                   => __( 'No items', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'way', array( 'post ', ' lp_course' ), $args );

}
add_action( 'init', 'custom_taxonomy', 0 );

添加了分类但是当我在我的帖子或课程中添加分类时,此错误出现在分类术语页面上:

在此处输入图像描述

4

1 回答 1

0

通过以下代码注册自定义帖子

<?php 
                /*Add the code below in function.php */ 
                function post_type_movie() {

                    $labels = array(
                        'name'                => _x( 'movie', 'Post Type General Name'), // it apper on top 
                        'singular_name'       => _x( 'movie', 'Post Type Singular Name'),
                        'menu_name'           => __( 'movie'),//name that display on menu
                        'parent_item_colon'   => __( 'Parent movie'),
                        'all_items'           => __( 'All movie'),
                        'view_item'           => __( 'View movie'),//it see on menu
                        'add_new_item'        => __( 'Add New movie'),//it apper on tp when try add new post
                        'add_new'             => __( 'Add New'),
                        'edit_item'           => __( 'Edit movie'),
                        'update_item'         => __( 'Update movie'),
                        'search_items'        => __( 'Search movie'),// it apper on top of the search
                        'not_found'           => __( 'Not Found'),
                        'not_found_in_trash'  => __( 'Not found in Trash'),
                    );

                // Set other options for Custom Post Type

                    $args = array(
                        'label'               => __( 'movie'),
                        'description'         => __( 'movie'),
                        'labels'              => $labels,
                        'supports'            => array( 'title','thumbnail','editor'),
                        'taxonomies'          => array('languge','type','time'),
                        'hierarchical'        => false,
                        'public'              => true,
                        'show_ui'             => true,
                        'show_in_menu'        => true,
                        'show_in_nav_menus'   => true,
                        'show_in_admin_bar'   => true,
                        'menu_position'       => 5,
                        'can_export'          => true,
                        'has_archive'         => true,
                        'exclude_from_search' => false,
                        'publicly_queryable'  => true,
                        'capability_type'     => 'page',
                    );

                    register_post_type( 'movie', $args );
                }
                add_action( 'init', 'post_type_movie', 0 );
            ?>

通过以下代码注册自定义分类

<?php
                function tax_languge() {
                     register_taxonomy(     'languge',//catagory naem
                                            'movie',//post type name
                      array(
                          'label' => __( 'Languge' ), //Label that shhow on backend
                          'rewrite' => array( 'slug' => 'languge' ),
                         'hierarchical' => true,
                      )
                    );
                }
                add_action( 'init', 'tax_languge', 0 );//call
            ?>

在这里发布类型电影(替换为您的赢)

Here taxonomy languge(替换为您的韩元)

于 2020-05-09T03:21:18.857 回答