wordpress自定义分类/类别发生了一个未识别的错误

时间:2017-11-08 04:19:01

标签: php wordpress categories taxonomy

我在wordpress中创建了一个自定义类别分类。并成功创建并在wordpress admin上显示。

问题:

  1. 我尝试添加新类别,但我需要先刷新页面以显示新创建的类别。

  2. 当我删除某个类别时,它会显示An unidentified error has occurred且该类别仍在列表中。我需要刷新页面,以便删除该类别。

  3. 这是我的代码

    // hook into the init action and call create_schedule_taxonomies when it fires
    add_action( 'init', 'create_schedule_taxonomies', 0 );
    
    // create two taxonomies, genres and writers for the post type "book"
    function create_schedule_taxonomies() {
        // Add new taxonomy, make it hierarchical (like categories)
        $labels = array(
            'name'              => _x( 'Categories', 'taxonomy general name' ),
            'singular_name'     => _x( 'Category', 'taxonomy singular name' ),
            'search_items'      => __( 'Search Category' ),
            'all_items'         => __( 'All Categories' ),
            'parent_item'       => __( 'Parent Category' ),
            'parent_item_colon' => __( 'Parent Category:' ),
            'edit_item'         => __( 'Edit Category' ),
            'update_item'       => __( 'Update Category' ),
            'add_new_item'      => __( 'Add New Category' ),
            'new_item_name'     => __( 'New Category' ),
            'menu_name'         => __( 'Categories' ),
            // more labels here...
        );
    
        $args = array(
            'hierarchical'      => true,
            'labels'            => $labels,
            'show_ui'           => true,
            'show_in_rest'      => true,
            'show_admin_column' => true,
            'query_var'         => true,
            'rewrite'           => array( 'slug' => 'schedule_category' ),
        );
        register_taxonomy( 'schedule_category', array( 'schedule' ), $args );
    }
    

    我们如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

function create_schedule_taxonomies() {
 register_taxonomy(  
   'schedule_category',  //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). 
   'schedule' ,        //post type name
   array(  
       'hierarchical' => true,  
       'label' => 'schedule categories',  //Display name
       'query_var' => true,
       'rewrite' => array(
           'slug' => 'schedule_category', // This controls the base slug that will display before each term
           'with_front' => false // Don't display the category base before 
       )
   )     );            }  add_action( 'init', 'create_schedule_taxonomies' );

答案 1 :(得分:0)

我在主题中面临同样的问题。

删除functions.php文件中php标记中的额外空格。

OR

删除不需要的插件。