# Show Custom Post Types in "At a Glance"

> Adds published counts for public custom post types (portfolio items, products, events and so on) to the At a Glance Dashboard widget.

- Type: PHP
- Runs: Admin only
- Category: [Dashboard](https://wpide.com/library/category/dashboard/)
- Tags: dashboard, custom-post-types, counts
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/custom-post-types-at-a-glance/

## Code

```php
add_filter( 'dashboard_glance_items', function ( $items ) {
    $post_types = get_post_types( array( 'public' => true, '_builtin' => false ), 'objects' );

    foreach ( $post_types as $type ) {
        $counts    = wp_count_posts( $type->name );
        $published = isset( $counts->publish ) ? (int) $counts->publish : 0;
        $label     = number_format_i18n( $published ) . ' ' . ( 1 === $published ? $type->labels->singular_name : $type->labels->name );

        if ( current_user_can( $type->cap->edit_posts ) ) {
            $items[] = sprintf( '<a class="%1$s-count" href="%2$s">%3$s</a>', esc_attr( $type->name ), esc_url( admin_url( 'edit.php?post_type=' . $type->name ) ), esc_html( $label ) );
        } else {
            $items[] = sprintf( '<span class="%1$s-count">%2$s</span>', esc_attr( $type->name ), esc_html( $label ) );
        }
    }

    return $items;
} );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Show Custom Post Types in "At a Glance"" 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/
