Hide Admin Posts from Contributors in WordPress

Posted on April 17, 2013 in WordPress Category

One of the most important things when you run a WordPress Blog and you have a lot of traffic is that many users or guests may want to write some articles on your blog. In this case you need let users register as Contributors, so you can review their articles and after publish them on your blog.

The common problem on most of WordPress Themes is that Contributors can see all posts in Admin Panel (Dashboard), even draft and pending posts of others. This is an annoying thing, because if you or your users may want to write new articles on your blog, they will be able to see all other posts in your Admin Panel, but they can't delete or edit any post.

Without Code

Below is the WordPress Admin Panel (Dashboard) of the contributor user, without the code in functions.php file. Note that he can see all posts, but can't edit anything.

Without Code

To resolve this problem you need to add a new function in your mighty functions.php file that will get the user role level and display a new query for the current user level. That means this function will disable contributors role to see posts that don't belong to them.

Writing the Code

In your theme folder search for the file name functions.php and write the code below:

// Hide Admin Posts from Contributors
function posts_for_current_author($query) {
	global $user_level;

	if($query->is_admin && $user_level < 2) {
		global $user_ID;
		$query->set('author', $user_ID);

	return $query;
add_filter('pre_get_posts', 'posts_for_current_author');

In the code above we get the user role level and we check if the user level is below 2 (you can check the WordPress Codex about User Levels). If the condition is true we'll get the user ID and tell the query to display only the posts from the current author ID, but if the condition is false everything will go back to normal for other users.

Check in Admin Panel

To check that your code is working, you can create a fake contributor account on your blog and log in Admin Panel. To make sure is working, delete your code from functions.php, refresh the page, check what is happening on posts page, then you can put the code again and test. You have a sample below:

With Code

Below is the Admin Panel (Dashboard) of the contributor user, with the code in functions.php file. Now the user can't see anything, only the posts counts.

Prevent Contributors from Seeing Others Posts inside Admin Panel in WordPress

The code above was tested with WordPress 3.5.1. It may work for newer version too.

Related Articles
  1. Fatima says:

    Perfect! Can we use this to do the same thing with comments? At the moment, contributors can see all comments in the moderation queue.

    • Hello Fatima,

      Sorry for my late reply. Yes, you can hide comments tab from contributors from admin panel too. I will write a special tutorial about this topic as it is important for other users.

      • Ravijit says:

        How to hide comment section from contributors? If you can give the code via comment, it would be really great.


Hint: Wrap your code syntax (html, css or others) between <pre> and </pre> tags. All comments are moderated.

× four = 8

Subscribe by E-mail

HTML-TUTS is built under the mighty WordPress platform.