I'm testing out the new Relationship functionality. I need to be able to essentially "assign" a CPT to a user. In this case, it's a "Case Study" and it needs to be assigned to a Dr that is one of the users. We don't want them to just be an author. ACF has the capability of doing an object lookup. I noticed that users was not one of the options under relationships.
Am I missing something?
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