Read-only taxonomy (user can assign term but can’t create or edit existing terms)

A bit late but thought this could use updating.

Create your custom taxonomy and add the terms you need, then go back to your register_taxonomy() function and set the capabilities argument (which itself accepts an array of capabilities). You can see how I setup sex for dogs which can only ever have two values–”Male” or “Female”, which I input. Now admins can only assign a dog to a sex but cannot add, delete, or edit the sexes.

register_taxonomy('sex', 'dog', array(
  'capabilities' => array(
    'manage_terms' => '',
    'edit_terms' => '',
    'delete_terms' => '',
    'assign_terms' => 'edit_posts'
  ),
  'label' => 'Sex',
  'labels' => array(
    'name' => 'Sex',
    'add_new_item' => 'Add New Sex',
    'new_item_name' => "Add New Sex"
  ),
  'public' => true,
  'show_admin_column' => true,
  'show_in_nav_menus' => false,
  'show_tagcloud' => false,
  'show_ui' => true,
  'hierarchical' => true
));

Works on hierarchical taxonomies; I did not try non-hierarchical but it should work there too.

Leave a Comment