Skip Navigation

[Resolved] Create dynamic dropdown of terms from custom taxonomy on CRED user forms

This support ticket is created 6 years, 7 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)

Author
Posts
#864922
2018-05-09 18_42_45-As Customer _ Price My Ride.png

Tell us what you are trying to do?

-Create a select dropdown in a CRED user create/edit form that is dynamically populated with the terms from my custom taxonomy "Regions". This is so users can select a region and only see content that relates to it.

Is there any documentation that you are following?

I have tried to implement this, but in my scenario it doesn't appear to work- just breaks my field- see screenshot (unless i've misunderstood the code): https://toolset.com/forums/topic/i-wish-i-could-load-a-custom-select-with-options-from-a-custom-taxonomy/

Thanks in advance for any assistance!

#865079

Hello,

The thread you mentioned above is outdated, it is different in the latest version of WordPress, you can try these:
1) Create a custom select user field, field title is "My Regions"

2) Create a custom taxonomy "Regions", the taxonomy slug is "regions"

3) Modify your PHP codes as below:


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

And test again.

More help:
https://developer.wordpress.org/reference/functions/get_terms/