• Resolved betadog

    (@betadog)


    Hi there,

    great plugin, saves me a lot time πŸ™‚

    One question though: is it possible to show the number of posts belonging to a Custom Post Type in the Dashboard’s “Right Now / At a glance” modul?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Tim Priebe

    (@timjpriebe)

    Found this online today, then saw your post. Hopefully this will help! It will also show custom taxonomies if you change

    $showTaxonomies = 0

    to

    $showTaxonomies = 1

    // Add custom taxonomies and custom post types counts to dashboard
    add_action( 'right_now_content_table_end', 'my_add_counts_to_dashboard' );
    
    function my_add_counts_to_dashboard() {
        $showTaxonomies = 0;
        // Custom taxonomies counts
        if ($showTaxonomies) {
            $taxonomies = get_taxonomies( array( '_builtin' => false ), 'objects' );
            foreach ( $taxonomies as $taxonomy ) {
                $num_terms  = wp_count_terms( $taxonomy->name );
                $num = number_format_i18n( $num_terms );
                $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name, $num_terms );
                $associated_post_type = $taxonomy->object_type;
                if ( current_user_can( 'manage_categories' ) ) {
                    $num = '<a href="edit-tags.php?taxonomy=' . $taxonomy->name . '&post_type=' . $associated_post_type[0] . '">' . $num . '</a>';
                    $text = '<a href="edit-tags.php?taxonomy=' . $taxonomy->name . '&post_type=' . $associated_post_type[0] . '">' . $text . '</a>';
                }
                echo '<td class="first b b-' . $taxonomy->name . 's">' . $num . '</td>';
                echo '<td class="t ' . $taxonomy->name . 's">' . $text . '</td>';
                echo '</tr><tr>';
            }
        }
        // Custom post types counts
        $post_types = get_post_types( array( '_builtin' => false ), 'objects' );
        foreach ( $post_types as $post_type ) {
            $num_posts = wp_count_posts( $post_type->name );
            $num = number_format_i18n( $num_posts->publish );
            $text = _n( $post_type->labels->singular_name, $post_type->labels->name, $num_posts->publish );
            if ( current_user_can( 'edit_posts' ) ) {
                $num = '<a href="edit.php?post_type=' . $post_type->name . '">' . $num . '</a>';
                $text = '<a href="edit.php?post_type=' . $post_type->name . '">' . $text . '</a>';
            }
            echo '<td class="first b b-' . $post_type->name . 's">' . $num . '</td>';
            echo '<td class="t ' . $post_type->name . 's">' . $text . '</td>';
            echo '</tr>';
    
            if ( $num_posts->pending > 0 ) {
                $num = number_format_i18n( $num_posts->pending );
                $text = _n( $post_type->labels->singular_name . ' pending', $post_type->labels->name . ' pending', $num_posts->pending );
                if ( current_user_can( 'edit_posts' ) ) {
                    $num = '<a href="edit.php?post_status=pending&post_type=' . $post_type->name . '">' . $num . '</a>';
                    $text = '<a href="edit.php?post_status=pending&post_type=' . $post_type->name . '">' . $text . '</a>';
                }
                echo '<td class="first b b-' . $post_type->name . 's">' . $num . '</td>';
                echo '<td class="t ' . $post_type->name . 's">' . $text . '</td>';
                echo '</tr>';
            }
        }
    }
    Thread Starter betadog

    (@betadog)

    Awesome, thanks a lot!

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Custom Post Type UI] Custom Post Types in Dashboard’ is closed to new replies.