Change WordPress user roles and capabilities Forums Give user access to plugin – how to Restriction content view on a page template

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2367
    dweb360
    Participant

    Hello,
    I have a page template to display my custom post type, how can restrict view to my custom post type using shortcode restrction

    I tried :

    <?php		
    echo do_shortcode( "[user_role_editor roles='administrateur']" );
    ?>

    but not working !

    Can i do ?
    If role ne “agent” -> display “You can’t see this content”
    If role eq “agent” -> Content is displayed

    Thank you

    #2370
    Vladimir
    Keymaster

    Hi,

    This shortcode does not produce a content itself. When you use it inside post content you enclose a part of content inside this shortcode, e.g.
    [user_role_editor ...]content to show[/user_role_editor]
    You can use this logic inside your template code:

    
    if (current_user_can('agent')) {
      echo 'You can see this';
    } else {
      echo 'You can not see this';
    }
    

    Or set this restriction for the ‘agent’ role using ‘Posts View’ button from posts view restriction module. You may use some category ID assigned to all post of that type for that.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.