Skip Navigation

[Resolved] Using category taxonomy as select option

This support ticket is created 6 years, 4 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Author
Posts
#915229

The code mentioned here - https://toolset.com/forums/topic/using-category-taxonomy-as-select-option/ didnt' work in the latest toolset and I was unable to ask question in the same thread.

Can you please provide the new/updated code.

#915234

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Let me try this on a test site and check whether it still works and see what needs to change if not.

You want to populate the options when you are editing the Types field of a post in the back-end admin screens, is that right?

#915576

Yes, i want populate the options in select from custom taxonomy term.

#915715

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I looked at the code in the linked post and there is a simple error which would prevent it from working, in the final line it needs to return the $options variable.

The updated code therefore looks like this:

add_filter( 'wpt_field_options', 'tssupp_fill_select', 10, 3);
function fill_select( $options, $title, $type ) {
    if ($title == 'My select field')  {
        $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
            );
        }
    }
    return $options;
}

You need to edit it for the name of your select field as well as the taxonomy.

Do you want to try that and let me know how you get on?

#915778

Thank you Nigel.

You forget to change function name "fill_select" so i changed it and code working fine.

Thank you for exact code.

#918768

This code is working fine outside of repeatable field group. But it is not working inside repeatable field group.

Can you please help me with the changes that needs to be done in the hooks so that it starts working inside repeatable field group.