I registered a taxonomy named districts, but when I add districts to nav menus, the nav menu items are invalid! Here is the code that registers the taxonomy:
function masallah() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
$labels = array(
'name' => _x( 'Districts', 'taxonomy general name' ),
'singular_name' => _x( 'District', 'taxonomy singular name' ),
'search_items' => __( 'Search Districts' ),
'all_items' => __( 'All Districts' ),
'parent_item' => __( 'Parent Districts' ),
'parent_item_colon' => __( 'Parent District:' ),
'edit_item' => __( 'Edit District' ),
'update_item' => __( 'Update District' ),
'add_new_item' => __( 'Add New District' ),
'new_item_name' => __( 'New Topic District' ),
'menu_name' => __( 'Districts' ),
);
// Now register the taxonomy
register_taxonomy('Districts',array('post'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'show_in_rest' => true,
'rewrite' => true,
'rewrite' => array( 'slug' => 'districts' ),
'has_archive' => true,
));
}
add_action( 'init', 'masallah', 0 );
I registered a taxonomy named districts, but when I add districts to nav menus, the nav menu items are invalid! Here is the code that registers the taxonomy:
function masallah() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
$labels = array(
'name' => _x( 'Districts', 'taxonomy general name' ),
'singular_name' => _x( 'District', 'taxonomy singular name' ),
'search_items' => __( 'Search Districts' ),
'all_items' => __( 'All Districts' ),
'parent_item' => __( 'Parent Districts' ),
'parent_item_colon' => __( 'Parent District:' ),
'edit_item' => __( 'Edit District' ),
'update_item' => __( 'Update District' ),
'add_new_item' => __( 'Add New District' ),
'new_item_name' => __( 'New Topic District' ),
'menu_name' => __( 'Districts' ),
);
// Now register the taxonomy
register_taxonomy('Districts',array('post'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'show_in_rest' => true,
'rewrite' => true,
'rewrite' => array( 'slug' => 'districts' ),
'has_archive' => true,
));
}
add_action( 'init', 'masallah', 0 );
Share
Improve this question
edited Mar 26, 2020 at 13:51
Tom J Nowell♦
61k7 gold badges79 silver badges148 bronze badges
asked Mar 26, 2020 at 1:19
knockknockknockknock
132 bronze badges
12
|
Show 7 more comments
1 Answer
Reset to default 0I've identified two issues, the first, this:
'rewrite' => true,
'rewrite' => array( 'slug' => 'districts' ),
Can just be this:
'rewrite' => array( 'slug' => 'districts' ),
And the second, the reason you get invalid menu items, is because districts
is being used as the rewrite slug, but, the internal namevof the taxonomy is Districts
.
Replacing Districts
with districts
as the internal name fixed the issue for me locally:
register_taxonomy( 'districts', array('post'), array(
It's a general rule of thumb to keep internal names of things lower case, you can always use the labels for what the user sees
rewrite
twice, but that would not cause the problems you are seeing, and it would not cause a000
taxonomy to appear. You need to switch to the default theme and disable all plugins, then re-enable them one by one to identify the plugin causing this, it is not standard WP behaviour. This also looks very familiar, did you ask this question using another account? – Tom J Nowell ♦ Commented Mar 26, 2020 at 13:16