Restrict authors to only be able to view their own posts in WordPress

Restrict authors to only be able to view their own posts in WordPress.

Snippet Type

Execute on Child Sites

Snippet

function wp_authors_posts_view( $wp_query ) {
    if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
        if ( !current_user_can( 'edit_others_posts' ) ) {
            global $current_user;
            $wp_query->set( 'author', $current_user->id );
        }
    }
}

add_filter('parse_query', 'wp_authors_posts_view' );

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.