简体   繁体   中英

An unidentified error has occurred wordpress custom taxonomy/category

I have create a custom category taxonomy in wordpress. And successfully created and display on wordpress admin.

Problems:

  1. I tried to add a new category, but I need to refresh the page first to show the newly created category.

  2. When I delete a category it shows that An unidentified error has occurred and the category is still on the list. I need to refresh the page so that the category will be removed.

here's my code

// 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 );
}

How can we solve that?

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' );

I faced the same problem in my theme.

Remove extra whitespace in php tag in functions.php file.

OR

Remove unwanted Plugins.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM