Home / Blog / WordPress
,

How to display Custom Post Types in “At A Glance” Meta Box ?

First published 3 Dec 2017. Tested again in November 2026 on WordPress 7.1.4 and PHP 8.4.

WordPress being the best and most popular CMS framework and due to its flexibility to add new features using a huge library of WordPress plugins, it is now possible to create any type of websites in WordPress. Most of these WordPress plugins and even custom development use WordPress feature of custom post types.

You might want to show all custom post types used on your website to display in “At a Glance” Metabox of WordPress dashboard. To display custom post types in “At a Glance” meta box add the code below to the functions.php file of your active theme.

Method 1: Simple Filter Hook

add_filter( 'dashboard_glance_items', 'add_cpt_to_glance' );

function add_cpt_to_glance( $items = array() ) {

    $post_types = array( 'your_cpt_slug', 'another_cpt_slug' ); // Add your CPT slugs

    foreach ( $post_types as $type ) {

        if ( ! post_type_exists( $type ) ) continue;

        $num_posts = wp_count_posts( $type );

        if ( $num_posts ) {
            $published = intval( $num_posts->publish );
            $post_type = get_post_type_object( $type );

            $text = _n(
                '%s ' . $post_type->labels->singular_name,
                '%s ' . $post_type->labels->name,
                $published,
                'your-textdomain'
            );

            $text = sprintf( $text, number_format_i18n( $published ) );

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

    return $items;
}

Method 2: Dynamic — Auto-detect All Public CPTs

add_filter( 'dashboard_glance_items', 'add_all_cpts_to_glance' );

function add_all_cpts_to_glance( $items = array() ) {

    $args = array(
        'public'   => true,
        '_builtin' => false, // Exclude built-in post types (post, page)
    );

    $post_types = get_post_types( $args, 'objects' );

    foreach ( $post_types as $post_type ) {

        $num_posts = wp_count_posts( $post_type->name );
        $published = intval( $num_posts->publish );

        $text = _n(
            '%s ' . $post_type->labels->singular_name,
            '%s ' . $post_type->labels->name,
            $published,
            'your-textdomain'
        );

        $text = sprintf( $text, number_format_i18n( $published ) );

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

    return $items;
}

View or fork this snippet on GitHub Gist.

Need this done on a live site? Exivon Tech takes on projects and audits, led by me.

Dhiren Patel

Principal Full-Stack Engineer · Founder, Exivon Tech

I’ve built and run enterprise web platforms and e-commerce for 13 years, and I built ShieldScope, a free WordPress security scanner, and Lede, a free block theme.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.