WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been asked to build a WordPress that limits access to posts with a particular custom post type based on the logged in users level. There will be a number of pre made user roles and they would like to choose which levels can view each post when the post is written.

What is the best way to do this?

share|improve this question
up vote 2 down vote accepted

There are two ways to do this. Almost any decent membership management plugin will enable you to restrict content to a given user role and plugins such as Role Scoper are even more flexible. For a more code-based solution you would add some variation of the following to the desired theme template files where ever needed:

<?php if(current_user_can('some_capability') ); ?>

and replace some_capability with whatever preset or custom capability is present for the lowest desired role. For instance, to restrict to Editors and Admins (assuming no customization):

<?php if(current_user_can('delete_others_posts') ); ?>

To add this functionality to any given post in the custom post type is a bit more challenging. You would be getting involved in adding actions and functions similar to this Smashing Magazine tutorial to restrict posts by username. All you would need to do is change from getting a list of users to getting a list of roles or capabilities. Again, there is a world of plugins that do this already...if your needs are not complex then you may not wish to reinvent the wheel.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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