【问题标题】:Assign Multiple Custom User Roles to a Custom Post Type将多个自定义用户角色分配给自定义帖子类型
【发布时间】: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


    【解决方案1】:

    这个插件可能就是你要找的 http://wordpress.org/extend/plugins/members/

    如果您不想使用插件,本教程也可能会有所帮助: http://shoutingwords.com/how-to-add-custom-user-roles-like-guest-author-to-your-wordpress-blog.html

    【讨论】:

    • 我实际上一直在使用帖子 2 帖子,它可以让您将帖子、页面和用户相互连接。感谢您的建议。
    猜你喜欢
    • 2016-12-04
    • 1970-01-01
    • 2020-12-29
    • 2021-06-09
    • 2018-03-10
    • 1970-01-01
    • 2017-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多