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?
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
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?
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
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...