Skip Navigation

[Resolved] Using category taxonomy as select option

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 7 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#512250

My apologizes if this has been answered before.

Is there a way to populate a select drop down, in my Post Field Group, that uses categories already setup in my wordpress page categories? I have a list of over 300 that need to be assigned to the drop down.

Thanks!

#512338

Hi! There's not currently a way to do this from the wp-admin area, but there is a PHP solution noted in another post:
https://toolset.com/forums/topic/i-wish-i-could-load-a-custom-select-with-options-from-a-custom-taxonomy/

add_filter( 'wpt_field_options', 'fill_select', 10, 3);
function fill_select( $options, $title, $type ) {
    if ($title == 'my-custom-select')  {
        $options = array();
        $args = array('hide_empty' => 'false');
        $terms = get_terms( array('my-taxonomy'), $args );
         
        foreach ($terms as $term) {
            $options[] = array(
                '#value' => $term->term_id,
                '#title' => $term->name
            );
        }
    }
}

Add this code to your functions.php file. Obviously you'll have to replace 'my-custom-select' and 'my-taxonomy' with the correct slugs for your site. Let me know if you need assistance, and I'll take a deeper look.

The forum ‘Types Community Support’ is closed to new topics and replies.