2

I'm trying to start myself off here but I can't get my head around it... How can I hide an author's post content/meta from everyone except the post author and admin? This is my scenario... Schools and teachers publish their own custom posts Schools/Admin can see all teachers posts but only the teacher who published the post can see their post, other teachers can't see other teacher's posts.

1
  • if(get_current_user_id() == get_the_author_id() || current_user_can('do admin stuff') ) {//show post}
    – ngearing
    Commented Jul 8, 2016 at 6:21

1 Answer 1

4

You can try below code -

<?php
    global $current_user;


     if ((is_user_logged_in() && $current_user->ID == $post->post_author) || current_user_can( 'manage_options' ))  {
        echo 'my post';
    }
?>

Check below link also-

https://codex.wordpress.org/Function_Reference/current_user_can

2
  • so manage_options is a capability that only the admin and the post's author can do?
    – Pete
    Commented Jul 8, 2016 at 9:35
  • 1
    No, manage_options is per default only available to Administrators.
    – kaiser
    Commented Jul 8, 2016 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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