# Published Posts Column in the Network Sites List

> Shows how many published posts each site has in Network Admin > Sites, cached for twelve hours so the list stays fast.

- Type: PHP
- Runs: Admin only
- Category: [Multisite](https://wpide.com/library/category/multisite/)
- Tags: network-admin, sites, columns, posts
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/ms-sites-post-count-column/

## Code

```php
if ( ! is_multisite() ) {
    return;
}

$wpide_post_type = 'post'; // Post type to count.

add_filter( 'wpmu_blogs_columns', function ( $columns ) {
    $columns['wpide_post_count'] = __( 'Posts' );

    return $columns;
} );

add_action( 'manage_sites_custom_column', function ( $column, $blog_id ) use ( $wpide_post_type ) {
    if ( 'wpide_post_count' !== $column ) {
        return;
    }

    $key   = 'wpide_post_count_' . (int) $blog_id . '_' . $wpide_post_type;
    $count = get_site_transient( $key );

    if ( false === $count ) {
        switch_to_blog( $blog_id );
        $counts = wp_count_posts( $wpide_post_type );
        $count  = isset( $counts->publish ) ? (int) $counts->publish : 0;
        restore_current_blog();
        set_site_transient( $key, $count, 12 * HOUR_IN_SECONDS );
    }

    echo esc_html( number_format_i18n( (int) $count ) );
}, 10, 2 );

add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) use ( $wpide_post_type ) {
    if ( $post->post_type === $wpide_post_type && ( 'publish' === $new_status || 'publish' === $old_status ) ) {
        delete_site_transient( 'wpide_post_count_' . get_current_blog_id() . '_' . $wpide_post_type );
    }
}, 10, 3 );
```

## Notes

Change $wpide_post_type to count pages or a custom post type instead.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Published Posts Column in the Network Sites List" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
