【WordPress】管理画面にてユーザー(投稿者)が他のユーザー(投稿者)の編集画面を見れないようにする

functions.phpに以下を貼りつける。
ユーザーを「寄稿者」で設定して試してみたら、うまくいきました。

参考サイトをそのままマネしました。

function exclude_other_posts( $wp_query ) {
if (!current_user_can('administrator')) {
if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) {
$post_type = get_post_type_object( $_REQUEST['post_type'] );
$cap_type = $post_type->cap->edit_other_posts;
} else {
$cap_type = 'edit_others_posts';
}
if ( is_admin() && $wp_query->is_main_query() && ! $wp_query->get( 'author' ) && ! current_user_can( $cap_type ) ) {
$user = wp_get_current_user();
$wp_query->set( 'author', $user->ID );
}
}
}
add_action( 'pre_get_posts', 'exclude_other_posts' );

標題の件で参考にした記事を下部に貼り付けておきます。

この記事を書いた人