Assign Multiple Custom User Roles to a Custom Post Type

Posted by OUHSD Webmaster on Stack Overflow See other posts from Stack Overflow or by OUHSD Webmaster
Published on 2012-09-07T18:56:20Z Indexed on 2012/09/09 21:38 UTC
Read the original article Hit count: 251

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!

© Stack Overflow or respective owner

Related posts about Wordpress

Related posts about custom-post-type