pre\\u get\\u posts正确。
来自的代码将阻止任何非管理员查看其他人的帖子。
http://blog.rutwick.com/display-only-the-posts-authored-by-the-current-wp-user-on-the-posts-page-in-the-back-end
要将其限制为仅1个帖子类型,您需要再添加一个条件并选中$typenow==“your\\u custom\\u post\\u type”:
add_action(\'pre_get_posts\', \'filter_posts_list\');
function filter_posts_list($query)
{
//$pagenow holds the name of the current page being viewed
global $pagenow, $typenow;
//$current_user uses the get_currentuserinfo() method to get the currently logged in user\'s data
global $current_user;
get_currentuserinfo();
//Shouldn\'t happen for the admin, but for any role with the edit_posts capability and only on the posts list page, that is edit.php
if(!current_user_can(\'administrator\') && current_user_can(\'edit_posts\') && (\'edit.php\' == $pagenow) && $typenow == \'your_custom_post_type\')
{
//global $query\'s set() method for setting the author as the current user\'s id
$query->set(\'author\', $current_user->ID);
}
}