I’m building a site for some army guys to share photos, and one thing keeps stumping me.
They have some photos that they’d like everyone who is signed up for the site to view, and others that just they can view. But they can’t be administrators.
The only help I can find is on only allowing certain user levels to POST to a category. I would like to basically restrict ‘subscribers’ from VIEWING some posts.
Not asking anyone to write something for me, but a point in the right direction would be awesome.
If I understand you have some categories, eg: ‘reserved’, ‘people’, ‘landscapes’, ‘personal’ and so on.
Now you want that subscribers can see posts in, e.g. ‘people’, ‘landscapes’ categories but not posts in ‘reserved’ and ‘personal’ categories.
This is relatively easy, just hook into
pre_get_posts
and if the request is for a post having that terms or the term archive disable the viewing.To disable you have different chanches, you can redirect, you can show 404 or you can show a custom template.
Below I’m sayng how to last option.
First of all create a template file, e.g.
not-allowed.php
and put in your theme folder.Then in
functions.php
use this code:Download and install the plug-in Restrict Categories.
Restrict certain categories for certain roles and post the photos in the appropriate categories.