0

I want to modify posts listing at back end?

Say, for a particular user, with role author, O want to list only few posts at posts listing. How can I do this?

6
  • Are you asking to filter the posts by author?
    – Nicole
    Commented Dec 16, 2011 at 14:59
  • Nope. I was to list only few posts when any particular user is loggedin, on back end post listing
    – I-M-JM
    Commented Dec 16, 2011 at 15:30
  • Yes it's possible using some filters available. But you might have to build your own displays for this role, because if you use the current capabilities provided in WP, then other posts will be visible (not editable) to the user logged in with a custom role. Are you interested in knowing how? Commented Dec 19, 2011 at 3:23
  • @ Rutwick Gangurde yes
    – I-M-JM
    Commented Dec 20, 2011 at 5:04
  • Cool... You have the answer below! Commented Dec 21, 2011 at 18:21

1 Answer 1

2

You can do this easily using the edit_posts_per_page hook or edit_{$post_type}_per_page hook for pages and custom post types

You can change based on the user role:

function my_edit_post_per_page_role_based( $per_page, $post_type ) {
    //admin sees 25 posts per page
    if (current_user_can('administrator')){return 25;}
    //editor sees 20 posts per page
    elseif(current_user_can('editor')){return 15;}
    //author sees 10 posts per page
    elseif(current_user_can('author')){return 10;}
    //contributor sees 5 posts per page
    elseif(current_user_can('contributor')){return 5;}
    return $per_page;
}

add_filter( 'edit_posts_per_page', 'my_edit_post_per_page_role_based' );

Or change base on user id:

function my_edit_post_per_page_user_based( $per_page, $post_type ) {
    global $current_user;
    get_currentuserinfo();
    //specific user id ex: user with the ID of 23
    if (23 == $current_user->ID){
        return 20;
    }
    //user group
    $can_see_only_10 = array(2,5,36,55,47); //array holding the group ids
    if (in_array($current_user->ID,$can_see_only_10)){
        return 10;
    }

    return $per_page;
}

add_filter( 'edit_posts_per_page', 'my_edit_post_per_page_user_based' );
4
  • based on example 2 that you provided, will it also restrict user to edit only those posts mentioned in array $can_see_only_10?
    – I-M-JM
    Commented Dec 26, 2011 at 11:02
  • @I-M-JM: not at all, its not restricing any thing , just setting the number of posts the user can see per page on the admin post listing.
    – Bainternet
    Commented Dec 26, 2011 at 12:04
  • you didn't understood my question at all
    – I-M-JM
    Commented Dec 28, 2011 at 4:25
  • 1
    that's the only thing anyone can understand from the question.
    – Bainternet
    Commented Dec 28, 2011 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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