-2

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 );
New contributor
knockknock is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • You need to write your question. You can't be asking questions with YouTube videos. – Jacob Peattie Mar 26 at 1:29
  • @JacobPeattie I dont know how to code videos, can I paste the code that comes from view button on winrar? Also I am not sure that you re-solve these code if you are not NEO from Matrix – knockknock Mar 26 at 1:41
  • 1
    Just describe the problem you're having! With words! – Jacob Peattie Mar 26 at 2:14
  • Questions must be self contained, if viewing the youtube video is necessary to even know what the question is then it will be closed as unclear what you're asking. It does not matter how effective or good the video is, the question must contain the question, in words, in english. – Tom J Nowell Mar 26 at 13:13
  • Having viewed the video, the only thing I can see wrong with your code is that you define rewrite twice, but that would not cause the problems you are seeing, and it would not cause a 000 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 Mar 26 at 13:16
0

I'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

  • you are right.thank you! I hope I will find you here if I get new error – knockknock Mar 26 at 14:04

Your Answer

knockknock is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.