Skip Navigation

[Resolved] Building group of custom field for custom post

This support ticket is created 2 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/Karachi (GMT+05:00)

Author
Posts
#2073109

Dear Sir/Madam,

I plan to build a website that is a learning platform. There are many courses, each course contain many lessons and each lesson contain a group of materials, the material can be different file format such as pdf, pptx, url, youtube link, etc.

How do I create a relationship between them?

One course - many lessons

One lesson - many materials

One material can be either pdf, ppt, URL, youtube link, etc

I don't have any idea how I can set up the relationship between lesson and material, I assume the material will be a repeatable field under lesson but how can I contain two fields including the file type, URL, and attachment? The file type should be a dropdown with all pdf, ppt, URL, youtube link as selection items. When the user selects pdf, ppt, then the next field will be the file field or URL when selecting URL or youtube link?

Could you advise how I can build it?

Best regards,

Kelvin.

#2073345

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Kelvin,

Thank you for contacting us and I'd be happy to assist.

Based on what you've shared, I'll recommend adding a new custom post type "Materials". Each file or link can be added to a single post in this custom post type.

Any custom fields like, type, link, and file/attachment can be added with this custom post type.

And then you can create a many-to-many relationship between "Lessons" and "Materials" post types so that a single material post can be used with multiple lessons if needed.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2076873

Dear Waqar,

Thanks for your reply. I want to explain what I want to do. I know how to associate a material to lesson and make the relationship to one lesson with many materials, I have no idea how I can firstly select the material type and then prompt the field type to the customer to fill the content, for example, if a customer selects the type as URL, then an input field with URL validation will be applied, if the type is a file, then the customer to upload a file. I don't want to create a custom post with many custom fields for different types of content, can I do that?

Best regards,

Kelvin.

#2079203

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

You won't have to add multiple post types for multiple types of materials and only 1 common custom post type "Materials" would be enough.

The first custom field for this custom post type can be "Material Type", where one can either select
- document (PDF, Docx, pptx etc)
OR
- link (URL, youtube link, Vimeo link, etc)

The other custom fields can be made available/unavailable conditionally based on the selection of this first field:
https://toolset.com/course-lesson/conditionally-display-custom-fields-in-wordpress-backend/

For example, if the material type is a document, then the file type custom field "Material File" becomes available.

And if the material type is a link, then a URL type custom field "Material Link" becomes available.

Likewise, when working with the front-end forms, you can use the conditional display to show/hide the fields, based on the selected material type:
https://toolset.com/course-lesson/conditional-display-for-form-inputs/

#2079261

Dear Waqar,

Many thanks for your reply. May I reconfirm what I learn from you? If I have four different types, then I should have a total of 5 custom fields, the first one a select field to allow the user to select the four types and then there are four custom fields for these four types, am I correct?

#2079271

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Yes, your understanding is correct.

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