Home › Toolset Professional Support › [Resolved] Hide access controlled posts in loop or display different content based on it
Problem:
Hide access controlled posts in loop or display different content based on it
Solution:
Toolset access offers a hook toolset_access_api_get_post_permissions using which you can check the current post permission. It returns the boolean value.
So, what if you create a custom shortcode and use it with [wpv-conditional] shortcode.
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/#checking-custom-shortcodes.
You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/hide-access-controlled-posts-in-loop-or-display-different-content-based-on-it/#post-919748
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/access-api-filters/#toolset_access_api_get_post_permissions
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
Related documentation:
This topic contains 1 reply, has 2 voices.
Last updated by Minesh 6 years, 6 months ago.
Assisted by: Minesh.
I have added a bunch of posts to a access controlled post group. Guests cannot see those posts (basically a simple membership site). When viewing the posts directly, everything works as expected.
Now I have build a custom search and I would like to either:
a) Hide restricted posts so the guests do not see them at all
b) Show the posts but add a visual hint so the guests know it is premium content and they won't be able to access those posts
If only b works, I would also need a way to filter for free/premium content.
I achieved something similar by adding a custom field to the post ("is-premium" checkbox) and checking it on all those posts which have the premium post group. Then I use conditional display and access in the loop but this feels very wrong:
[wpv-conditional if="( $(wpcf-is-premium) eq '1' )"]
[toolset_access role="Guest" operator="allow"]You need a premium account to see this[/toolset_access]
[toolset_access role="Guest" operator="deny"]Here is your content:...[/toolset_access]
[/wpv-conditional]
Is there a way to check for the post group instead of adding the custom field? I think it will get very hard to housekeep the field and the post group at the same time.
Hello. Thank you for contacting the Toolset support.
Well - Toolset access offers a hook toolset_access_api_get_post_permissions using which you can check the current post permission. It returns the boolean value.
So, what if you create a custom shortcode and use it with [wpv-conditional] shortcode.
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/#checking-custom-shortcodes
More info:
=> https://toolset.com/documentation/programmer-reference/access-api-filters/#toolset_access_api_get_post_permissions
Please feel free to get in touch with me if you need further help with your query.