【发布时间】:2012-09-01 16:15:40
【问题描述】:
好的,情况就是这样......我正在开发我的商业网站。将有一个工作/投资组合区域。 “工作”是一种自定义帖子类型。 “设计师”是自定义用户角色。 “客户”是自定义用户角色。
在创建新的“作品”帖子时,我希望能够选择“设计师”和“客户”来分配给作品,就像我会为普通的帖子分配作者一样。
我尝试了 answer 中的方法,但它对我不起作用。 ) 我把它放在了我的 functions.php 文件中。
` add_filter('wp_dropdown_users', 'test'); 功能测试($输出) { 全球 $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;
}
`
任何帮助将不胜感激!
【问题讨论】:
标签: wordpress custom-post-type user-roles