Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在wordpress中,我如何确保用户只看到自己的帖子?_Wordpress - Fatal编程技术网

在wordpress中,我如何确保用户只看到自己的帖子?

在wordpress中,我如何确保用户只看到自己的帖子?,wordpress,Wordpress,我在我的博客中添加了一些自定义角色。它们工作得很好,功能正如我所指定的。问题是每个用户都有一个“所有”帖子的列表在他的帖子窗口中。他只能编辑自己的帖子,但可以看到其他用户写的帖子 如何向角色添加限制(或任何其他方式)以确保用户只看到自己的帖子?尝试将其粘贴到functions.php文件中。任何地方,可能在底部远离其他功能。这将限制用户看到不属于他们的帖子 我希望这对你有用!:) function posts_for_current_author($query) { global $pa

我在我的博客中添加了一些自定义角色。它们工作得很好,功能正如我所指定的。问题是每个用户都有一个“所有”帖子的列表在他的帖子窗口中。他只能编辑自己的帖子,但可以看到其他用户写的帖子


如何向角色添加限制(或任何其他方式)以确保用户只看到自己的帖子?

尝试将其粘贴到functions.php文件中。任何地方,可能在底部远离其他功能。这将限制用户看到不属于他们的帖子

我希望这对你有用!:)

function posts_for_current_author($query) {
    global $pagenow;

    if( 'edit.php' != $pagenow || !$query->is_admin )
        return $query;

    if( !current_user_can( 'manage_options' ) ) {
        global $user_ID;
        $query->set('author', $user_ID );
    }
    return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');