Skip Navigation

[Resolved] Filtering Options by Taxonomy when Setting up Post Relationships

This support ticket is created 5 years, 10 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/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by KentS9937 5 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#915489

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?

#915669

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

#915989

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.

#916085

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

#916754

Thanks for your help.

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