The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 8 years ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.
I use toolset for managing meetings between students and teachers of several schools
The relationships of content:
-----------------------------------------------
school > students
school > teachers
school > meetings
------------------------------------------------
school > students > meetings
school > teachers > meetings
When I create a form for meetings (post-type), i get fiels like that:
[cred_field field='_wpcf_belongs_teacher_id' value='']
[cred_field field='_wpcf_belongs_student_id' value='']
In the select field of the form are all students and all teachers from all schools.
How do i get only the specific students and teachers of a given school?
I still can't put my finger on it, I will need to work out a solution for you.
The one thing I am missing from your description is how do we know which school we want to limit the post relationships to?
The form which creates meeting posts, is it aware of which school it is creating posts for before it is rendered?
This will require some custom code on the front end, and depending on how and when the school is determined it may be possible to limit the teachers and students passed to JavaScript to just those from the required school, or it may be necessary to pass all teachers and all students and the schools they belong to.
Sorry, I unfortunately forgot to explain that the information which school is currently logged in comes from a session variable ($_SESSION['school_id']).
Is there a way to use it in the cred form?
That won't help when the CRED form is generated, but it does help when it comes to customising the parent post options once the form has been sent to the browser.
What is involved writing some PHP which for the relevant page where the CRED form is added will create an array of the relevant teachers and students that are possible parents of the to-be-created meeting given the school available from your session variable, and then make this available to jQuery on the front end using wp_localize_script.
We can then use jQuery to remove the existing options from the select boxes and rebuild them to include just the possible parent posts according to the school using the array passed from our PHP code.
Does that sound like a viable solution?
Are you able to have a go yourself, or do you need some help implementing it?