0

I have created a custom taxonomy called Country to collect posts (even from different categories) under country terms. I used the following code, and I created terms with no problem:

function country_init() {
    register_taxonomy(
        'country',
        'post',
        array(
            'label' => __( 'Country' ),
            'show_ui' => true,
            'update_count_callback' => '_update_post_term_count',
            'show_admin_column' => true,
            'show_in_nav_menus' => true,
            'rewrite' => array( 'slug' => 'country' ),
            'capabilities' => array(
                'manage_terms' => 'manage_options',
                'edit_terms'   => 'manage_options',             
                'assign_terms' => 'edit_guides',
            )
        )
    );
}
add_action( 'init', 'country_init' );

I am not able to choose those terms while creating a new post. The widget area shows the box named country, but toggling nothing as in the following picture. And there are no country boxes while creating menus or widgets.

empty widget

Is there something wrong with the code?

  • try removing the capabilities array and see if that changes anything.. – Bainternet Oct 29 '14 at 12:10
  • 1
    I had to change 'hierarchical' to true in my taxonomy definition to fix this problem. – rg89 May 15 '18 at 0:40
2

Seems like its creating some conflict. Can you try with this code ?

add_action( 'init', 'country_init' );

function country_init() {

    $labels = array( 
        'name' => _x( 'Countries', 'countries' ),
        'singular_name' => _x( 'Country', 'countries' ),
        'search_items' => _x( 'Search Countries', 'countries' ),
        'popular_items' => _x( 'Popular Countries', 'countries' ),
        'all_items' => _x( 'All Countries', 'countries' ),
        'parent_item' => _x( 'Parent Country', 'countries' ),
        'parent_item_colon' => _x( 'Parent Country:', 'countries' ),
        'edit_item' => _x( 'Edit Country', 'countries' ),
        'update_item' => _x( 'Update Country', 'countries' ),
        'add_new_item' => _x( 'Add New Country', 'countries' ),
        'new_item_name' => _x( 'New Country', 'countries' ),
        'separate_items_with_commas' => _x( 'Separate countries with commas', 'countries' ),
        'add_or_remove_items' => _x( 'Add or remove countries', 'countries' ),
        'choose_from_most_used' => _x( 'Choose from the most used countries', 'countries' ),
        'menu_name' => _x( 'Countries', 'countries' ),
    );

    $args = array( 
        'labels' => $labels,
        'public' => true,
        'show_in_nav_menus' => true,
        'show_ui' => true,
        'show_tagcloud' => true,
        'show_admin_column' => false,
        'hierarchical' => true,

        'rewrite' => true,
        'query_var' => true
    );

    register_taxonomy( 'countries', array('post'), $args );
}
  • Thanks for that it extended the capability of it. But why it is not showing in the Widget or Menu area? – Kareem Oct 29 '14 at 14:19
  • 1
    It must be showing in the Menus area. try checking the "Screen Options" on the top-right corner of the admin screen. – Subharanjan Oct 29 '14 at 14:38

Your Answer

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.