Skip Navigation

[Resolved] Can I configure Access so subscribers can only view their own posts?

This thread is resolved. Here is a description of the problem and solution.

Problem:
how allow subscribers to read their own posts only

Solution (include the steps to follow here):
You can use a wpv-conditional as example.
Let's say you use a Content template for all your Posts, in this content template you could check if the current logged in user is the author of the post.
A shortCode like this could work:

[wpv-conditional if="( '[wpv-current-user info="id"]' eq '[wpv-post-author format="meta" meta="ID"]' )"]
//Your content here
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Eric 5 years, 5 months ago.

Assigned support staff: Beda.

Author
Posts
#341620

I am trying to create a system, hopefully with Access, that will allow subscribers to view/update/delete their own posts (in this case a custom post type). Currently I'm able to restrict the CRUD, but not the display. How do I prevent subscribers from seeing other subscriber's posts.

#341770

Thank you for contacting us here in the Support Forum

I understand you already successfully handled the part of "management", means CRED and WP Admin access.

Now you want to hide all Posts on the Front End from users that are NOT authors of the post.

You should be able to do that as follows:
(you can't do it with Access because the "Read" permission is for all users of a role)

You can use a wpv-conditional as example.
Let's say you use a Content template for all your Posts, in this content template you could check if the current logged in user is the author of the post.

If yes, display whatever you want of the Posts content.
Otherwise you could craft a nice "custom Message" to advice the user why he / she can't see the Post.

A shortCode like this could work:

[wpv-conditional if="( '[wpv-current-user info="id"]' eq '[wpv-post-author format="meta" meta="ID"]' )"]
//Your content here
[/wpv-conditional]

This above can be used as long you have Views enabled, in any Post, content template or View.

Please let me know if you need further infos about this.

Thank you for your patience.

#341881

Thanks Beda. That's a great start. The subscribers can now only see their own post content. They can, however, still see the titles of other subscriber posts. Is that because the titles are outside of the content template? I suppose I could hide those titles with CSS, then add "[wpv-post-title]" inside the wpv-conditional block, but I wonder if there's a cleaner method. Any ideas?

Thanks!
Eric

#342256

Yes, the title is not on your content and if you used a "if" statement in a Post body, title is not affected.

Now, if you use a Content Template the situation depends on your theme and how it renders the content.

Perhaps you have Theme Options to NOT display Post Title on single posts, some themes have them.

If so you would need to check "Do not display Post Title", and add the Post Title IN your Content template WITHIN the "if" statement.

The thing is, Post Title is not part of the_content, and Content Templates are replaying the_content function.
https://codex.wordpress.org/Function_Reference/the_content

That means, everything your theme displays additionally to the_content, is still shown on the single post even if you use a content template.

You could also use Layouts to fully edit your Templates, then, everything within the Theme's Loop will be replaced with The Layouts content.
https://toolset.com/documentation/user-guides/layouts-theme-integration/

Please let me know if you need further infos about this.

Thank you for your patience.

#342602

Thanks for the explanation. I understand now.
Eric