Support Forum
Support › MB Relationships › Relationship vs Post Field / CPTs vs Groups
Hi,
I'm new to MB and here's my newbie question.
I need to list the courses and for each one add a form for the student to attend the course.
Here is the data structure of the course.
I need to output (ideally also in the admin tables):
* All the courses, each with all their terms (including dates and places)
* All the atendees including their courses' details (course, date, place)
* Filter all the atendees for each course (acrosss all the terms)
* Filter all the atendees for individual course's term (just one term)
How to structure this situation in MB?
<h2>Option 1 - Terms as a CPT</h2>
I can use CPT for each term and then use these relationships:
* connect the term with it's parent course
* connect the term with the place
* connect the attendee with the term
Unfortunatelly it might get too complicated to manage when editing the courses. I would have to create the term separately and THEN connect it to the course via relationship selectbox. As far as I know, there's no possibility to add new CPT's posts inside other CPTs (in this case to add a new term while editing the course).
Atendee would then select the term from CPT list (which I would need to filter for each course).
<h2>Option 2 - Terms as a Cloneable Group</h2>
In this case the terms would be a part of the Course CPT as a custom field. Also I would have to use the post field to select the place, as I cannot place a relationship field to the group repeater.
This solution would be much better to manage for the admin, as he could see and create all the terms right in the course detail.
On the other hand I'm not sure if this wouldn't turn into a nighmare when querying all the views I need. I'm also not sure how could I assign the atendee to the term (now inside the group's repeater).
I also didn't manage to output the terms from the repeater to the admin table - all I can se there is a list of "Array" (but their count is correct, it respondes to the number of the terms).
Concerning the scale - there will be lower tens of courses, each with 1-5 terms, so the number of terms won't be high. On the other hand, the number of the atendees could get higher, as each term can have up to 20 students.
I apologize for quite long and complex question, but could you give me an advice and some deeper insight, especially concerning the performance?
Thank you in advance
Petr
Hi Petr,
Thanks for reaching out.
You can create 3 custom taxonomies or 3 CPTs (term, place, attendee) as the term of the course. With MB Relationships you can create relations and connect between them easily.
There is one note, for option 2. The group
field type is used for storing data, not for querying. So in case you need to query posts by taxonomy in a group, it is very hard to do. You can read more here https://metabox.io/create-group-of-custom-fields-with-meta-box-group/
Hi Long,
Well I know, I can do everything you mentioned, I wanted to know, how to do it the best way possible. Let mi phrase my questions differently then:
1. More interactive connections between related CPTs
Is there a way I can add and edit records from other related CPTs within the parent CPT? Basically I want my Terms table for each Course to behave the same way like a qroup field repeater - while editing the Course I want to flawlessly add and edit its Terms.
2. Differences between custom fields settings
Do these custom fields settings make any difference for the query efficency (especially concerning the group clones)?
- Save data in a custom table
- Clone as multiple
3. How to output group field data in the admin table column?
As I mentioned before, I didn't succeed in outputting the group subfields to the admin column. The only output was several lines of the word "Array" (the number of lines coredponded with the group clones). How should I setup my settings?
Concerning the queries: I need to query and filter almost everything:
- all courses including terms
- available terms for the course
- available places for the course
- terms and courses by the place
- atendees belonging to the course
- atendees belonging to the term of the course
- atendees belonging to the place
etc...
And yes - there might be some taxonomies belonging to the terms itselves (like one-day, weekend, semestral, ...). So I should probably go with Terms as CPT, but editing them outside the parent Course would be highly confusing for the editors. How to deal with this?
Thanks
Petr
Hi Petr,
- Save field value in the custom table helps you to query posts by predefined value, it's a little bit different from a regular WP query. Please read more on the documentation https://docs.metabox.io/extensions/mb-custom-table/#query-posts-with-wp_query
- "Clone as multiple" setting helps you to query post by cloneable field's value. Please read more here https://metabox.io/introducing-clone-as-multiple-feature/
But in general, you should not use group
field to query posts. It should use to store value and get it when you have the post ID.
If you create all terms as CPTs, you can follow this documentaiton to create nested query https://docs.metabox.io/extensions/mb-relationships/#nesting