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 Jul 8 '16 at 6:21
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 Jul 8 '16 at 9:35
  • 1
    No, manage_options is per default only available to Administrators. – kaiser Jul 8 '16 at 10:08

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.