Created
November 28, 2013 07:21
-
-
Save joglomedia/7688366 to your computer and use it in GitHub Desktop.
WordPress limit access to posts/pages by user roles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
Ref: http://wordpress.stackexchange.com/questions/60582/limit-access-to-posts-pages-by-user-roles | |
<?php | |
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 | |
the_title(); | |
the_content(); | |
} else { // text to show instead the post | |
echo 'this post is private, only contributor can view it'; | |
} | |
} else { // this is visible to all | |
the_title(); | |
the_content(); | |
} | |
endwhile; | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment