Displaying Only Author’s Posts from the Admin Panel

If you have a multi-author based WordPress site, by default everyone would see who wrote which post from the post administration panel. Even though authors cannot edit others post but it shows up automatically. Authors would see others posts that he or she really don’t need to.

If you are the administrator of the site, you may want to hide others posts to any individual author and display only author’s posts which I find to be more reasonable. You can easily implement this feature on your site simply placing the following snippet on your theme’s functions.php file.

<?php
add_action('load-edit.php','display_authors_posts_only');
function display_authors_posts_only() {
   global $user_ID;
   if (current_user_can('edit_others_pages')) { return; }
   if (!isset( $_GET['author'])) { wp_redirect(add_query_arg('author', $user_ID));
   exit; } }
?>

What we are doing here is pretty simple. We are creating a function to check the current users ID and also checking if the logged in user has the capability to “edit_others_pages”. If user is capable of editing others pages (only Super Admin, Adminstrator and Editor Can do that), the function would do nothing but if it is an author it will load only the author’s posts.

You can modify the snippet in many ways, but you need to understand the various users role in WordPress and their capabilities. You can visit the WordPress Codex link provided below to better understand this issue.

Related Link: WordPress Codex.

Today In History

  •  
  •  

Comment

1 Comment

    Neymar LeittyPublished: 3 years ago

    Thanks! Helped me a lot 🙂
    Continue with your tutorials.

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from Postable, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.