Skip Navigation

[Resolved] I want to create a nationality list as a user field via the Types plugin

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to create a dropdown for custom taxonomy.

Solution:
To load taxonomy terms from existing taxonomy to a select type user field you need to add the following code to your current theme's functions.php file.

Code Example : https://toolset.com/forums/topic/i-want-to-create-a-nationality-list-as-a-user-field-via-the-types-plugin/#post-372018

Where:
Replace "user-nationality" with your user custom field title and "vehicle-type" with your original taxonomy slug.

This support ticket is created 8 years, 1 month 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by nuZ 8 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#371962

nuZ

I am trying to: create some custom user fields. One of them is the nationality, which contains a list of over 200 countries. However, if I use the User Fields of Types Plugin, and add new field - Select, I figure out that I can only add those countries one by one. Is there any smarter way to define this custom field? Is it possible to link to the existing taxonomy for example?

Thanks a lot!

#372018

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

To load taxonomy terms from existing taxonomy to a select type user field you need to add following code to your current theme's functions.php file.

//dynamically populate select field from Types
add_filter( 'wpt_field_options', 'add_some_options', 10, 3);
function add_some_options( $options, $title, $type ){
		
    switch( $title ){
        case 'user-nationality':
         
            $options = array();
            $tax = get_terms ('vehicle-type');
			         
            foreach ($tax as $term) {
                $options[] = array(
                    '#value' => $term->term_id,
                    '#title' => $term->name,
                );
            }
            break;
    }
    return $options;
}

Where:
Replace "user-nationality" with your user custom field title and "vehicle-type" with your original taxonomy slug.

I hope above solution will help you to resolve your issue.

#373234

nuZ

Thanks a lot! Very helpful

It works perfectly for the 'Select' type user field. But it does not work for the checkboxes (multiple choices) type field. Is there a way to make it work as well?

#373285

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As your original question is resolved. May I kindly ask you please to open a new ticket for your additional question? This will help other users with similar problems to find solutions when searching the forum.

#373388

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