为了只显示用户是作者的页面,我使用pre_get_posts
更改查询的操作。
add_action( \'pre_get_posts\', function ( $wp_query ) {
$user = wp_get_current_user();
global $pagenow;
if ( !empty($user->roles) ) {
// BackEnd AND Entity "Page" AND "any role other than administrator" AND not New post
if ( is_admin() && \'page\' == $wp_query->query[\'post_type\'] && !in_array( \'administrator\', (array) $user->roles ) && !in_array($pagenow, [\'post.php\', \'post-new.php\']) ) {
$wp_query->set( \'author\', $user->ID );
add_filter( \'views_edit-page\', \'__return_empty_array\' ); // To hide filters in top of the list page ( All(X) | Publish(X) | Draft(X) )
}
}
});