I have two CPT:
- Teacher
- Student
As we know, one teacher can have more students. It is possible to assign the teacher to each student while creating CPT with the next steps:
- Create a Student
- Select Teacher inside Student post type
- Save the Teacher For example, it can be done with ACF:
The question is: Is it possible to create Student posts directly inside Teacher post? It will be much easier for admin to create all this stuff in this way. I need a field that will allow to create Students and assign them to Teacher inside Teacher post type. Below is a screenshot of mockup what I need to achieve:
The Student and Teacher will have different HTML templates so there is a need for them be different post types. I have not found any information about my issue and suspect that this is impossible to do in WordPress. Any help is appreciated :) Thanks in advance.
I have two CPT:
- Teacher
- Student
As we know, one teacher can have more students. It is possible to assign the teacher to each student while creating CPT with the next steps:
- Create a Student
- Select Teacher inside Student post type
- Save the Teacher For example, it can be done with ACF:
The question is: Is it possible to create Student posts directly inside Teacher post? It will be much easier for admin to create all this stuff in this way. I need a field that will allow to create Students and assign them to Teacher inside Teacher post type. Below is a screenshot of mockup what I need to achieve:
The Student and Teacher will have different HTML templates so there is a need for them be different post types. I have not found any information about my issue and suspect that this is impossible to do in WordPress. Any help is appreciated :) Thanks in advance.
Share Improve this question asked Jan 15, 2021 at 21:59 Misha KysliukMisha Kysliuk 111 bronze badge 4- This is very possible and I’ve done things like this. You’re not actually making a post type inside another post type, what you’re really doing is associating a new ‘post_type_b’ with ‘post_type_a’. Question, are you letting teachers use the WP edit screen to do this or are they going to use a front end form/page/template? – Tony Djukic Commented Jan 16, 2021 at 16:00
- There’s even lots of ways you can approach this, you can assign student IDs to an array in a teachers meta_data. You can auto generate a custom taxonomy when teachers are created and then assign that term to each student as they get created, this would all students to have multiple teachers, etc. – Tony Djukic Commented Jan 16, 2021 at 16:06
- @TonyDjukic I was talking about creating Students while saving Teacher post type. It is pretty easy to bind these two post types if saving them separately. – Misha Kysliuk Commented Jan 17, 2021 at 16:59
- I understood that and it is possible. I would recommend doing it with AJAX. You understand though why your question is difficult to accurately answer though, right? It’s very vague and open ended; “Is it possible?” Yes. In a number of different ways. – Tony Djukic Commented Jan 17, 2021 at 19:04
1 Answer
Reset to default 0As I understood you want to be able to add Students from the Teachers post type and assign them directly to the current teacher.
Is it impossible? I don't think so but definitely not an easy task to pull off. You are going to have to manually write all the code the outputs a form inside the Teachers post type and create a Student according to the data filled once the post is published/Updated or by ajax as a separate form inside the page. (And I am not sure how viable this is).
Unless each student have only one Teacher (and I doubt this is the case) you can use a repeater inside the Teachers CPT instead of another CPT for the Students.
I would suggest you stick to it as it is and just add each Teacher and Student from there own panel while having AFC field link them together as the amount of work needed to achieve this is not worth it.