Do you want to restrict authors to view only posts they created within the admin panel? While there’s probably a plugin for this, we have created a quick code snippet that you can use to restrict authors to view only posts they created in WordPress.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

function posts_for_current_author($query) { global $pagenow; if( 'edit.php' != $pagenow || !$query->is_admin ) return $query; if( !current_user_can( 'manage_options' ) ) { global $user_ID; $query->set('author', $user_ID ); } return $query; } add_filter('pre_get_posts', 'posts_for_current_author');

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 15 best content marketing tools and how to create a contact form in WordPress.