Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to hide/remove the numbers behind the Edit screen in the backend.

All (30) | Published (22) | Draft (5) | Pending (2) | Trash (1)

As I am running a multi author blog and each author has just access to its own posts, I dont want to publish the cumulated information of all authors.

With the following code the views are completely unset, but I dont want to remove the whole functionality:

function remove__views( $views ) {
unset($views['all']);
unset($views['publish']);
unset($views['trash']);
return $views;
}
add_action( 'views_edit-post',  'remove_views' );
add_action( 'views_edit-movie', 'remove_views' );

Has anybody an idea, how I can either hide/remove the numbers behind the edit screen or - at best - to show only the numbers related to each author?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

There is, unfortunately, no "pretty" way to do this (i.e. without using string replacing or rewriting a big chunck of functionality). So, resorting to preg_replace...

We'll need to filter the links, and it's good to see that you've already found the proper filters! Looping through the views and using a regular expression, we can remove the element containing the post count. Implementing this for posts, you'll need something like this:

add_filter( 'views_edit-post', 'wpse149143_edit_posts_views' );

function wpse149143_edit_posts_views( $views ) {
    foreach ( $views as $index => $view ) {
        $views[ $index ] = preg_replace( '/ <span class="count">\([0-9]+\)<\/span>/', '', $view );
    }

    return $views;
}
share|improve this answer
    
Thanks for the code, its working great. If there is a solution to show only the numbers related to each author - instead of hiding all counts - please let me know. –  Traveler Jun 10 at 12:52

We had the same problem today. A pretty solution is perhaps not obvious, but not impossible either.

Here is the code we use to show only the counts related to each author. Users with rights to edit the posts of other users will still see the full count.

 add_filter('wp_count_posts', 'wpse149143_wp_count_posts', 10, 3);


    /**
     * Modify returned post counts by status for the current post type.
     *  Only retrieve counts of own items for users without rights to 'edit_others_posts'
     *
     * @since   26 June 2014
     * @version 26 June 2014
     * @author  W. van Dam
     *
     * @notes   Based on wp_count_posts (wp-includes/posts.php)
     *
     * @param object $counts An object containing the current post_type's post
     *                       counts by status.
     * @param string $type   Post type.
     * @param string $perm   The permission to determine if the posts are 'readable'
     *                       by the current user.
     * 
     * @return object Number of posts for each status
     */
    function wpse149143_wp_count_posts( $counts, $type, $perm ) {
        global $wpdb;

        // We only want to modify the counts shown in admin and depending on $perm being 'readable' 
        if ( ! is_admin() || 'readable' !== $perm ) {
            return $counts;
        }

        // Only modify the counts if the user is not allowed to edit the posts of others
        $post_type_object = get_post_type_object($type);
        if (current_user_can( $post_type_object->cap->edit_others_posts ) ) {
            return $counts;
        }

        $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s AND (post_author = %d) GROUP BY post_status";
        $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type, get_current_user_id() ), ARRAY_A );
        $counts = array_fill_keys( get_post_stati(), 0 );

        foreach ( $results as $row ) {
            $counts[ $row['post_status'] ] = $row['num_posts'];
        }

        return (object) $counts;
    }
share|improve this answer

I think the easiest way would be to just hide them with CSS, you could try something like this:

add_action( 'admin_head', 'wpse145565_hide_post_count' );

function wpse145565_hide_post_count() {
    $css  = '<style>';
    $css .= '.subsubsub a .count { display: none; }';
    $css .= '</style>';

    echo $css;
}

Basically the function adds a style tag to the head of the admin section that sets the display property of the text count as none.

share|improve this answer

Your Answer

 
discard

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.