I create a role and set capabilities for a group of user.

$userdata = array(
$uid = wp_insert_user($userdata);
    $blogger = new WP_User($uid);
    //add role
    $capabilities =  array(
        'read' => true,
        'publish_posts' => true,
        'edit_published_posts' => true,
        'delete_published_posts' => true,
        'edit_posts' => true,
        'delete_posts' => true
    add_role('blogger_simple', 'blogger_simple', $capabilities);
    $blogger -> set_role('blogger_simple');

Now, the user create successfully. I logged in to the system, and create one post , just one post.

Then I click the menu Post --> All Posts and found three columns there Mine(number) All(number) Published(number).

I click All(2), find I can see others posts?
I click Published(2), still 2 posts one is mine the other is by admin What's more, I search post, got the same results.

That's not I want, I just want to get my posts not by admin and all other user's post. How do I get just my posts when I click All/Published link below All posts menu, and also the search box.


You will need to filter that list.

function alter_views_wpse_103613($views) {
  $role = 'blogger_simple';
  if (current_user_can($role)) {
    $views = array('mine'=>$views['mine']);
  return $views;
add_filter( 'views_edit-post', 'alter_views_wpse_103613' );

That filter list is part of the WP_List_Table class if you want to investigate more. Look for the views method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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