Assign Multiple Custom User Roles to a Custom Post Type
- by OUHSD Webmaster
Okay here's the situation.... I'm working on a my business website. There will be a work/portfolio area. "Work" is a custom post type. "Designer" is a custom user role. "Client" is a custom user role.
In creating a new "Work" post I would like to be able to select both a "designer" and "Client" to assign to the piece of work, as I would assign an author to a regular ol' post.
I tried the method from this answer but it did not work for me. ) I placed it in my functions.php file.
` add_filter('wp_dropdown_users', 'test');
function test($output)
{
global $post;
//Doing it only for the custom post type
if($post->post_type == 'work')
{
$users = get_users(array('role'=>'designer'));
//We're forming a new select with our values, you can add an option
//with value 1, and text as 'admin' if you want the admin to be listed as well,
//optionally you can use a simple string replace trick to insert your options,
//if you don't want to override the defaults
$output .= "<select id='post_author_override' name='post_author_override' class=''>";
foreach($users as $user)
{
$output .= "<option value='".$user->id."'>".$user->user_login."</option>";
}
$output .= "</select>";
}
return $output;
}
`
Any help would be extremely appreciated!