Restrict a WordPress Post Type to Viewing by Logged-in Users
We had this question from a PublishPress user:
How do I make it so that, by default, all authenticated users can read content of a specific post type but anonymous users cannot?
This is possible with the PublishPress plugins.
I'll show you how to configure your WordPress site so that all one post type is automatically blocked from pubic access. I'll use The Events Calendar as an example, but this could work with almost any plugin.
- Install the PublishPress Permissions Pro plugin.
- Go to Permissions > Settings in your WordPress admin menu.
- Click the “Core” tab.
- Check the box for “Events” under “Filtered Post Types”.
- Click “Save Changes”.
- Click the “Editing” tab.
- Change the default visibility for “Events” to “Private”. You can also check the “Lock” box which means that users will not be able to change the visibility.
Now you can test out this visibility setting:
- Create a new event.
- There will be a “Visibility” box in the right sidebar and it will be set to “Private”. This is part of the Permissions plugin.
- Click “Publish” when your event is ready.
- When you go to the main “Events” screen, your new post will be marked as “Private.”
How to control access to Private content
- Go to “Capabilities” in your WordPress admin menu.
- Using the dropdown in the top-left corner, choose the role you want to edit.
- In the center of the screen, in the “Reading” area, you can give this role access to your Private content:
You can set this for all the roles on your site. Once you are finished, anyone who is logged-in will be able to see these “Private” events.
What will site visitors see?
If someone comes to your site, they will see no events at all. Even if the visitor knows the URL of an event, all they will see is a “Page Not Found” message.