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'm looking for a way to protect content by user roles.


you have to be registered to view posts (frontend).

If a user is a subscriber he can read post 1, 2 and 3, but if the user is a contributor he can view post 1,2,3 and 4,5,6...

does anyone know how I can do this?

share|improve this question
up vote 1 down vote accepted

Although I haven't used this personally you are probably looking at a plugin like this

Seems to provide all the functionality you have requested above.

share|improve this answer
I've just tried this one. Doesnt do what I need, but almost... or.... to complicated!! – Demilio Aug 2 '12 at 8:30
I've just installed the plugin and it's very easy to set up access to certain posts for subscribers and then give more access to contributors. – Vince Pettit Aug 2 '12 at 8:48
yes, backend, but I need to define access frontend. Who can or can not read posts, defined bu user roles. – Demilio Aug 2 '12 at 8:56
Yes you can do that with the plug in (See screenshot at s.wordpress.org/extend/plugins/advanced-access-manager/…) – Vince Pettit Aug 2 '12 at 9:22
yes, thanks man!! – Demilio Aug 2 '12 at 9:31

you can use such conditions to show private posts only to logged in users with role contributor. Now you only need to make post private to make that post available for contributor.

    if ( have_posts() ) : while ( have_posts() ) : the_post();
        $private = get_post_custom_values("private");
        if (isset($private[0]) && $private == "true") {

            if ( current_user_can( 'contributor' ) ) { //passing role to it may sometime not work
            } else {            // text to show instead the post
                echo 'this post is private, only contributor can view it';

        } else {        // this is visible to all

share|improve this answer

To achieve something like that you can make some posts private and show them just to the logged in users, first you need to add a custom field, you can name it "private" and value it "True". Then add replace the default WP loop with this code snippet:

    <?php if (have_posts()) : while (have_posts()) : the_post();

    $private = get_post_custom_values("private");
    if (isset($private[0]) && $private == "true") {
        if (is_user_logged_in()) {
            // Display private post to logged user
    } else {
        // Display public post to everyone

endwhile; endif; ?>
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.