I have only frontend block, and I need restrict category to only logged in User, so The Author create category and this category view only this current author, not another user. Its here any way/plugin in wordpress?

edit1: My question is simmilar, like here: Restricting Users to view only Custom Taxonomies they have entered? but I don´t know how it implement for my.

edit2: I add meta terms field to taxonomie with this plugin: https://fuc.wordpress.org/plugins/wp-custom-taxonomy-meta/ So I parrent user meta with taxonomie (category). How can I implement get_terms and wp_dropdown_cats and show taxonomie for only current logged in Author (Frontend User)?


Inside while loop of single.php you can put condition like this

if(in_category('Catetory_slug')){ //Specifying category whom we don't want to see by no logged in users
    if(is_user_logged_in()){      //Checking if user logged in or not
        //code inside single.php
        Echo "You need to login to view this post."; //message for no logged in users

This can be done for other template of theme files like we did for single.php.


If you want one user couldn't see posts of another user then you can use these two functions to achieve this

Use following inside while loop

//storing autor's display name in variable
$post_author = get_the_author();    
$current_user = wp_get_current_user();
//storing autor's display name in variable
$current_user_info = $current_user->display_name;
//Chacking if bot strings (display names) are equal or not
if (strcmp($post_author, $current_user_info) == 0) {  

     //Your Code to display post's content


You can also put if condition on ID instead of display name. For that you need to make 2 changes in above code

  1. replace get_the_author() function with get_the_author_meta()
  2. and replace following line of code

    $current_user_info = $current_user->display_name;

with this

$current_user_info = $current_user->ID; 

To know more read about this functions in detail in my given link.

  • Hi,With this code all logged in user views that some categories. But I need this restrict: User1 create his category (frontend), and User2 create another category, but User1 cannot see category from User2 and another users, and User2 cannot see category from User1 and another users. Is here any way? – heroj May 17 '17 at 11:18
  • Answer has been updated, check if this helps. – Rishabh May 18 '17 at 6:43
  • Hi, Thank You Rishabh, but its for "one user couldn't see posts of another user" and I need "one user couldn't see Category (so taxonomie) of another user", can I use this code for category? I know how restrict contents (its plugin for this), but I dont know how restrict category. For ex: User1 have movie1 and User2 have too category with name movie1, but its differnt from Users1 movie1 category. So each User can create own categories, and another user can´t see it. Its possible? – heroj May 18 '17 at 22:38
  • I try this plugin: wordpress.org/plugins/restrict-categories, but there admin must select category. I need automaticaly parrent Category to their frontend Author. – heroj May 18 '17 at 22:39
  • You mean you don't want to one user can see category in dashboard while creating new posts? Categories that appears right side on posts edit page? If yes, then sorry I can't help you in that with code. This can be done with any plugin. And plugin that I know or you know, in those plugin admin has to make selection for other users like which category will be visible to whom. – Rishabh May 19 '17 at 4:33

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.