你需要使用动作钩pre_get_posts
.
有关详细信息,请参见注释,并将自定义帖子类型修改为您自己的类型:
add_action( \'pre_get_posts\', \'filter_cpt_listing_by_author_wpse_89233\' );
function filter_cpt_listing_by_author_wpse_89233( $wp_query_obj )
{
// Front end, do nothing
if( !is_admin() )
return;
global $current_user, $pagenow;
wp_get_current_user();
// http://php.net/manual/en/function.is-a.php
if( !is_a( $current_user, \'WP_User\') )
return;
// Not the correct screen, bail out
if( \'edit.php\' != $pagenow )
return;
// Not the correct post type, bail out
if( \'portfolio\' != $wp_query_obj->query[\'post_type\'] )
return;
// If the user is not administrator, filter the post listing
if( !current_user_can( \'delete_plugins\' ) )
$wp_query_obj->set(\'author\', $current_user->ID );
}
您会注意到,需要更正所有已发布的草稿的帖子数量
请参阅
solution here.