2

I am using wordpress latest version and running a multi author blog. When any user (contributor or author) go to edit.php, they are seeing posts and post counts of other users. I hide the posts of other authors by this code,

function posts_for_current_author($query) {
    global $user_level;

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

return $query;

} add_filter('pre_get_posts', 'posts_for_current_author');

Now they are not seeing other posts but seeing total post counts and published posts count. See screenshot:

editor.php screen of contributors

I wan't to hide all and published section from users edit.php and other section will count only own posts. Please help me to do this!

  • 1
    @CarlosCosta If you have a question, please post it as one, referring if necessary to this one. – cjbj Aug 23 '16 at 17:56
  • I found this answer solved the problem of updating the post count to exclude other authors' posts - it might help anyone else who has this problem too: wordpress.stackexchange.com/questions/178236/… – FluffyKitten Jul 8 '17 at 19:33
1

In order to remove a specific All() and Pubished() post counts from Posts-editor page you can:

// Create a specific hook
add_filter("views_edit-post", 'custom_editor_counts', 10, 1);


function custom_editor_counts($views) {
    // var_dump($views) to check other array elements that you can hide.
    unset($views['all']);
    unset($views['publish']);
    return $views;
}

Lets go more advanced and remove All() from Posts-editor admin table and Published() from Pages-editor admin table.

// Create a hook per specific Admin Editor Table-view inside loop
foreach( array( 'edit-post', 'edit-page') as $hook )
    add_filter( "views_$hook" , 'custom_editor_counts', 10, 1);


function custom_editor_counts($views) {

    // Get current admin page view from global variable 
    global $current_screen;

    // Remove count-tab per specific screen viewed.
    switch ($current_screen->id) {
        case 'edit-post':
            unset($views['all']);
            break;
        case 'edit-page':
            unset($views['publish']);
            break;
    }

    return $views;
}

Refferences: [Hide the post count behind Post Views (Remove All, Published and Trashed) in Custom Post Type]

UPDATE

Updated an answer with a code how to update posts count for specific user, excluding "all" and "publish" views. Recently tested on WP 4.3 twentyfifteen.

add_filter("views_edit-post", 'custom_editor_counts', 10, 1);

function custom_editor_counts($views) {
    $iCurrentUserID = get_current_user_id();

    if ($iCurrentUserID !== 0) {

        global $wpdb;

        foreach ($views as $index => $view) {
            if (in_array($index, array('all', 'publish')))
                continue;
            $viewValue = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type='post' AND post_author=$iCurrentUserID AND post_status='$index'");
            $views[$index] = preg_replace('/\(.+\)/U', '(' . $viewValue . ')', $views[$index]);
        }

        unset($views['all']);
        unset($views['publish']);
    }
    return $views;
}
  • can't update count. [i.imgur.com/3miD9Es.jpg] There seeing draft 1 but there is no post in draft for this author. Tell me brief please. – akarim Aug 26 '15 at 16:39
  • Please check anwser updated – Ignat B. Aug 26 '15 at 18:38

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.