Show Authors Only Their Own Posts in Admin Lists
Users who cannot edit other people's posts, like authors and contributors, see only their own items in the admin lists.
Opens WPIDE on
Code
add_action( 'pre_get_posts', function ( $query ) {
global $pagenow;
if ( ! is_admin() || ! $query->is_main_query() || 'edit.php' !== $pagenow ) {
return;
}
$post_type = $query->get( 'post_type' ) ? $query->get( 'post_type' ) : 'post';
$object = get_post_type_object( is_array( $post_type ) ? reset( $post_type ) : $post_type );
if ( $object && ! current_user_can( $object->cap->edit_others_posts ) ) {
$query->set( 'author', get_current_user_id() );
}
} );
Notes
The counts above the list (All, Published) still include other people's posts.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.