I have two post types; HR-Profiles and Interview Forms. I have created a one-many relationship which allows for assigning a specific individual (HR-Profile) as the recruiter for each Interview Form. HR-Profiles entries have a taxonomy assigned which is their position. When creating or editing the Interview Form and setting the HR-Profile relationship, I want to filter the choices in the drop down so only those HR-Profiles with a specific Position taxonomy value are available for selection. I'm trying to only show HR-Profiles with the Position taxonomy value of Supervisor or Manager.
In the Form I'm using the following to allow for selecting the HR-Profile. This works but is listing all of the HR-Profiles in the drop down.
<div class="col-sm-2">Interviewer</div>
<div class="col-sm-4">[cred_field field='@in-person-interview-recruiter.parent' select_text='Select Recruiter' class='form-control' output='bootstrap']</div>
</div>
How can I filter the options in this drop down by taxonomy?
Hello,
There isn't such a built-in feature within Toolset Forms, see document:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field
No such kind of option to filter the options in this drop down by taxonomy.
As a workaround, you can setup a generic field:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field
Create a view to list "HR-Profiles" posts, filter by the taxonomy term
https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/
output the view's result as options of above generic field,
user can select one of the option and submit the form, then you can use CRED action hook cred_save_data
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
to save the post relationship:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
Thanks for your suggestions. I anticipate needing to implement this solution on many forms, some with multiple fields on the form. As I understand the process with the API and cred_save_data, I will need to specifically name the generic fields and post fields in the functions.php code. Are there any tricks to avoid doing this for each instance? The code will get pretty large. There will be many forms (different post types) where I need to do the identical filtering of employee profiles to only list those with a specific taxonomy (such as recruiter). I'm trying to think of different approaches which might scale better? I appreciate any recommendations you might have.
Yes, you are right, since it is not a built-in feature of Toolset plugin, you will need to specifically name the generic fields and post fields in the functions.php code, in your case, it might need lots of custom codes, I don't think there is any other tricks to avoid doing this for each instance