Skip Navigation

[Resolved] Limit access to CPT to specific user

This support ticket is created 3 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 3 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1867091

Tell us what you are trying to do?

Is there a tutorial or example of best way to limit access to a specific set of CPT instances to a specific user. They may or may not be the author.

The use case here is similar to woo-commerce. A user can only see their own orders.

In this case, we will have a set of custom posts that will be linked to a specific user. We will have a page that only displays the ones they have access to.

Be great if Nigel can pick this up.

#1867469

Hello,

There isn't such kind of built-in feature within Toolset plugins.

In your case, as a workaround, you can consider to setup many-to-many relationship between WordPress users and posts:
https://toolset.com/documentation/legacy-features/views-plugin/how-to-create-custom-searches-and-relationships-for-users/

For example:
1) Create a custom post type "Member", one user has only one "Member" post, each "Member" post's author is different WP user.
2) Setup many-to-many relationship between "Member" and your "CPT"
3) Edit each "CPT" post, connect it with other "Member" posts
4) After user login your website, show him a WP page, in this page display a nested view:
a) Parent post view:
- Query "Member" posts
- Filter by post's author is same as logged-in user
- In views' loop display below child post view
b) Child post view:
- Query "CPT" posts
- Filter by post type relationship between "Member" and your "CPT"
- In views' loop, display "CPT" information

#1867637

Thanks Lao. Kind of what I thought. Thanks for pointers on approach.

Be nice if the dev team considered. It would unlock a range of applications.

#1868527

Toolset Access plugin is based on WordPress Roles and Capabilities, see WP document:
https://wordpress.org/support/article/roles-and-capabilities/

There isn't such kind of built-in feature within WordPress too, so I don't think we can add such feature into Toolset Access plugin, but you can add a feature request for it, our developers will evaluate it.
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/