用户允许创建/更新仅自己的帖子

时间:2018-11-27 08:06:01

标签: wordpress

我创建了一个自定义帖子类型(即公司资料),我希望允许用户仅创建或更新他们拥有的资料。我该怎么办?

还有一个钩子或方法可以用来确定用户是否是内容的作者,如果用户创建了内容,然后在编辑配置文件上重定向。

1 个答案:

答案 0 :(得分:0)

此功能可能会为您提供帮助。

它检查用户是否可以编辑其他人的帖子,

,如果不能,则只能在仪表板上显示他/她自己的帖子。

/*only allow editors and admin to see all posts.*/
function posts_for_current_author($query) {
    global $pagenow;
    if( 'edit.php' != $pagenow || !$query->is_admin )
        return $query;
        if( !current_user_can( 'edit_others_posts' ) ) {
            global $user_ID;
            $query->set('author', $user_ID );
        }
    return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');

您可以使用类似的方法来从用户个人资料重定向。

相关问题