0

I have a problem. I would like to have "groups" to give access to posts. And "subgroups" to show different sections of that post.

A simple example: "Only users from Group 1 can access to Post 1. And if the user belongs to subgroup 1, can read first paragraph".

How can I do it?

1

First you need to make group and subgroup. You can use wordpress existing User Role or you can make custom user role (group) by own. Members is a nice plugin to create custom role.

For example your main group is "Group1" and subgroup is "Subgroup1". First you need to check current user role (Group of user). After that you can show full content for "Group1". And first paragraph for Subgroup1 group, I think use excerpt is the best solution.

So full code should be like.

<?php
global $current_user;
$current_user = array_shift($current_user->roles);

if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h1><?php the_title(); ?></h1>
    <?php 
        if($current_user == 'group1') {
            the_content();
        }elseif ($current_user == 'subgroup1') {
            the_excerpt();
        }else {
            // if user is not under group1 or subgroup1 
            // you can do here what you like
            // For example redirec home page. Or show message please register
        }
    ?>
<?php endwhile; endif; ?>
1
  • Is it possible to have a hierarchical role system or permissions system? – user1443216 Jul 24 '16 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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