WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to display only authors own posts in dashboard all posts section. As of now it displays everything.

I found some code here which is written by @t31os Its working correctly.

function posts_for_current_author($query) {
    global $user_level;

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

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

But user_level is deprecated. So can anyone modify the code for new version? Thanks

share|improve this question
Are you aware of the Roles and Capabilities that wordpress offers by default? Especially Author - Somebody who can publish and manage their own posts – hakre Dec 31 '11 at 18:21
Yes i'm aware of roles and caps. But i'm trying to give permissions to submit content for all registered users (subscribers). But I don't want to list all posts – Giri Dec 31 '11 at 18:29
Okay, I see. As $user_level is deprecated, you might be able to check for it's role(s) then instead. – hakre Dec 31 '11 at 18:36
Can you give me the code? I tried but its not working. – Giri Dec 31 '11 at 19:15
You only need to replace the $user_level with the appropriate role, see Roles and Capabilities: User Levels which level relates to which role. – hakre Dec 31 '11 at 19:20
up vote 4 down vote accepted

The following worked for me to show only the current user's posts in the admin

add_action( 'load-edit.php', 'posts_for_current_author' );
function posts_for_current_author() {
    global $user_ID;

    /*if current user is an 'administrator' do nothing*/
    //if ( current_user_can( 'add_users' ) ) return;

    /*if current user is an 'administrator' or 'editor' do nothing*/
    if ( current_user_can( 'edit_others_pages' ) ) return;

    if ( ! isset( $_GET['author'] ) ) {
        wp_redirect( add_query_arg( 'author', $user_ID ) );


It can be edited pretty easily if the restriction should only happen for users in a particular role.

share|improve this answer
You are a diamond mate. It worked like a charm. Thank you so much – Giri Dec 31 '11 at 20:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.