Skip Navigation

[Resolved] Dynamically populate custom fields

This support ticket is created 5 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
- 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 1 reply, has 2 voices.

Last updated by Luo Yang 5 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1317525

Hi, I am trying to populate a custom dropdown field with the users from my website.

How can I do this?

Thank you

#1317535

Hello,

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