Skip Navigation

[Resolved] Dropdown that shows all users

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

This topic contains 4 replies, has 2 voices.

Last updated by Chris 7 years ago.

Assisted by: Luo Yang.

Author
Posts
#590023
Edit Group ‹ Huddle for Care — WordPress.png

Tell us what you are trying to do?
I am trying to create a field so when I'm creating a new post I can choose from all users. I should be able to choose a few users if wanted.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#590063

Dear Chris,

There isn't such a built-in feature or existed documentation for it, but you can try with Types filter hook wpt_field_options, for example:
1) Create a custom select field, the field title is "user id"
2) Add below PHP codes in your theme/functions.php:

add_filter( 'wpt_field_options', 'add_some_options', 10, 3);
function add_some_options( $options, $title, $type )
{
    switch( $title )
    {
    case 'user id':
        $args = array(
            'orderby' => 'display_name',
            'fields' => array( 'ID', 'display_name')
        );
        foreach( get_users($args) as $user ) {
            $options[] = array(
                '#value' => $user->ID,
                '#title' => $user->display_name,
            );
        }
        break;
    }
    return $options;
}

If you need to get some specific users, please check wordpress document:
get_users()
https://codex.wordpress.org/Function_Reference/get_users

#590250
Edit Story  Add Collaborators — WordPress.png

Thanks. Working but the dropdown is standard and I cannot add multiple people, only allowing 1. I need a multi-select dropdown. See screenshot.

Anyway this can happen?

#590415

For the new question: I need a multi-select dropdown...

There isn't such a built-in feature of custom multi-select dropdown within Types plugin, and the filter hook "wpt_field_options" only works for the custom select field and radio field, both are single choice option field.
If you agree we can take it as a feature request, our developers will evaluate it. thanks

#590679

Do put in this request. This seems like a must for a custom type builder as advanced and Toolset.

I'll have to hack the field then...