Skip Navigation

[Resolved] Using Access Control in relationship custom post

This support ticket is created 3 years, 3 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 3 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#2136661
Screenshot 2021-08-08 at 8.29.58 AM.png

Dear Sir/Madam,

I have several custom post relationship and repeatable field group. Refer to the screenshot, I want to display the course details if WP users (as student or teacher role) has been enrolled or assigned to the class, I know how to get the course information and repeatable custom field group data, how can I set the access control the restrict non-enrolled student or unassigned teacher to access the course details when I visit the class page. Student or teacher will visit a page /myclass?class-id=999 to access the course details and materials, this page contain a View to display the course details and materials according to the class id and linked course.

Please advise how I can do that.

Best regards,

Kelvin.

#2137931

Hello, in this case I do not think Toolset Access will be able to provide the type of access control you need. Toolset Access works by restricting access to content based on Post Group and User role. However in this case, you need to restrict access based on whether or not the current logged-in User is the author of any Enrollment post that is connected to the current class post by post relationship.
You could create a View of Enrollment Posts, filtered by post author is the same as the current logged-in User, and also filtered by post relationship, where the Enrollment Post is related to the post where the View is shown. If there are results found in the View, then you know the current User is enrolled in the current Class. You can show the class information in this case. If no results are found, then you know the current User is not enrolled in the current class. You can use the "no items found" section of the View to display a message like "Only enrolled users can see this content"