While creating a new plugin for a WordPress site I came across a problem trying to setup a custom post_type. I wanted to create a custom post_type, a custom taxonomy, and a custom role to assign my new taxonomy to the custom post_type. I wanted the users with this new role to be restricted to this custom post_type and not be able to edit/add/delete posts so I didn’t give this role the edit_posts capability. When I got everything set up I noticed that my new role could not add taxonomy tags to my custom post_type without the edit_posts capability. After hours of Googling and posting topics to the wordpress.org support forums I finally figured it out by digging down into the core. This is one of the best new features of wordpress 3 but there is a lack of documentation on how to do it so I’m going to give you some code that will accomplish the objective. Below is a link to my code for creating everything you will need. It gives the admin role the capability to manage the custom taxonomy and the custom role the capability to add taxonomy tags. To give the custom role the ability to manage the custom taxonomy just give it the manage_couponbooks capability.

http://pastebin.com/FfftYVYS

In this code I have created my custom post_type, custom taxonomy, and custom role. The important part is the capabilities argument to the custom taxonomy.

'capabilities' => array('assign_terms'=>'edit_coupons','manage_terms' => 'manage_couponbooks','edit_terms' => 'manage_couponbooks','delete_terms' => 'manage_couponbooks'),

This maps the edit_terms capability to manage_couponbooks which allows the role to mange my new taxonomy. Seems pretty simple but the documentation is not very good. Hopefully this is useful and someone will be able to forgo the hours I spent trying to figure it out.

Leave a Reply