Skip Navigation

[Resolved] Fetch data from related custom post

This support ticket is created 2 years, 9 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 2 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#2126069
course-classes.jpg

Dear Sir/Madam,

Please refer to the attached screenshot, a student can have many classes and each class is related to only one course, the course contains many materials and the class also contain its materials.

How can I show all materials that belong to the class and also to the course when a student visits a class? Could you please let me know how I can do using the Views and API code?

Best regards,

Kelvin.

#2126193

Hello,

In your case, you can try these:
1) Setup four post types:
- students
- classes
- courses
- materials

2) Setup three relationships:
- Many-to-many relationship between "students" and "classes"
- One-to-one relationship between "classes" and "courses"
- One-to-many relationship between "courses" and "materials"

In the single "classes" posts, you can display a nested view:
a) Parent post view "related courses post":
- Query courses posts
- Filter by relationship between "classes" and "courses"
- In view's loop, display below child post view
b) Child post view "related materials posts":
- Query materials posts
- Filter by relationship between "classes" and "courses"
- In view's loop, display below materials post information

More help:
https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items

If you are going to use custom PHP codes, please check our document:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

#2126529

Dear Luo Yang,

Thanks for your reply, I have a question why it is recommended to have the student post type? I create the student role and assign the role to the WP user, is that ok?

Regarding to One-to-one relationship between "classes" and "courses", basically one course can be reused to many classes and one class can only be associated to one course, why you recommend to have one-to-one relationship between "classes" and "courses"?

Best regards,

Kelvin

#2127483

I suggested it since you mentioned these:
each class is related to only one course

Then you can change it to:
One-to-many relationship between "courses" and "classes"

It depends on yourself, my suggestions are just for your reference.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.