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).
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/
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?
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.
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).
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,