Skip Navigation

[Resolved] Preselcting Categories based of Custom field selection

This thread is resolved. Here is a description of the problem and solution.

Problem:

Is it possible to pre-select or hide certain category options upon selecting a value in a custom drop down field in a CPT.

Solution:

There isn't such kind of built-in feature within Toolset plugins, you might consider custom codes, for example

https://toolset.com/forums/topic/preselcting-categories-based-of-custom-field-selection/#post-2287341

Relevant Documentation:

https://developer.wordpress.org/reference/hooks/save_post/

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.

Our next available supporter will start replying to tickets in about 3.56 hours from now. Thank you for your understanding.

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 2 replies, has 2 voices.

Last updated by fleurP 1 year, 3 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#2286781

Is it possible to pre-select or hide certain category options upon selecting a value in a custom drop down field in a CPT.

#2287341

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hello,

There isn't such kind of built-in feature within Toolset plugins, you might consider custom codes, for example, after user choose an option in the custom select field, and save the post, you can use WordPress action hook "save_post" to trigger a PHP function:
https://developer.wordpress.org/reference/hooks/save_post/
In this PHP function, get the custom select field value:
https://developer.wordpress.org/reference/functions/get_post_meta/
And setup the term's value of your custom taxonomy:
https://developer.wordpress.org/reference/functions/wp_set_object_terms/

#2287431

Thanks Luo Yang