Skip Navigation

[Resolved] Add a Post Field that is a select dropdown of available Categories

This support ticket is created 7 years, 11 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 5 replies, has 2 voices.

Last updated by Luo Yang 7 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#394374

I am trying to: Add a Post Field into a Custom Post Type that is a select dropdown of available categories. Posts themselves can have multiple categories selected, and we are looking to capture just one of those here to use as a Primary Category value in another View. This is would be a single select dropdown that provides a value such as 'wpv-primary-category'.

Instead, I got: A select dropdown option, but can only add options manually, as opposed to a dynamically populated list of options (available categories).

#394465

Dear eric,

It is expected result, you will need to manually setup options of custom select field in wordpress admin side, in your case I suggest you replace it with a custom taxonomy, for example:
See our document:
WordPress Custom Taxonomies
https://toolset.com/documentation/user-guides/create-custom-taxonomies/

#394695

I think you misunderstood me. We have the categories setup already as standard WordPress categories. All we want to do is populate a Types select field with all categories listed under the parent category "Markets". Our Types select field slug -> primary-related-projects-category.

It seems like this post gets us close: https://toolset.com/forums/topic/i-want-to-create-a-nationality-list-as-a-user-field-via-the-types-plugin/#post-372018

Can you help?

#394890

Yes, it is possible to modify the options in custom select field with filter hook wpt_field_options, but it needs custom PHP codes, according to our new Customer Support Policy, we do not provide custom codes support:
https://toolset.com/toolset-support-policy/

I suggest you debug your PHP codes manually, you can use set the parameter "parent" as 0 to get the top level terms:
https://developer.wordpress.org/reference/functions/get_terms/
'parent'
(int|string) Parent term ID to retrieve direct-child terms of.

#396525
Screen Shot 2016-05-09 at 10.47.52 AM.png

Thanks, we're getting very close. The category select is returning the category 'ID' where we need the category 'slug' in order to update the view properly. How can we modify the select to return the slug value, rather than the id?

Alternatively, if there is a way to filter the taxonomy by ID then that would work as well, but only category 'name' and 'slug' seem to be available in the Taxonomy Filter (screenshot attached).

#396680

Please check the wordpress document:
https://developer.wordpress.org/reference/functions/get_terms/
If you need output the term slug as result, you can simply modify your PHP codes, from:
'#value' => $term->term_id,
To:
'#value' => $term->slug,

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