Add Custom Post Type Totals to the “Right Now” Box

There’s a pretty convenient “at a glance” widget in the Dashboard called Right Now. But if you’re using any custom post types, you may have noticed they won’t show up there.

Naturally, we can fix that:

add_action( 'right_now_content_table_end', 'post_type_totals_rightnow' );
function post_type_totals_rightnow() {    
    $post_types = get_post_types( array( '_builtin' => false ), 'objects' ); 
    if (count($post_types) > 0)
    foreach( $post_types as $pt => $args ) {
        $url = 'edit.php?post_type='.$pt;
        echo '<tr><td class="b"><a href="'. $url .'">'. wp_count_posts( $pt )->publish .'</a></td><td class="t"><a href="'. $url .'">'. $args->labels->name .'</a></td></tr>';
    }
}

2 thoughts on “Add Custom Post Type Totals to the “Right Now” Box”

  1. Hey there, I have a question for you in regards to adding a similar option to wp-admin bar.. I’m working on a plugin right now for a premium job theme, and I’m trying to add job count and resume count as one of the options on the menu. Now the method I have works, but it adds additional numbers between the and

    I really don’t know why it does this, do you think you can help me on this?..

    Here’s my method:

    function add_jobroller_jobs_bar_menu() { $opts = get_option( ‘add_jobroller_jobs_bar_menu’ ); global $wp_admin_bar;

    if ( !is_super_admin() || !is_admin_bar_showing() ) return;

    $wp_admin_bar->add_menu( array( ‘id’ => ‘jobroller_job_links’,’title’ => __(‘Jobs Menu’, ‘jraba’),
    ‘href’ =>get_home_url( $blog->userblog_id, ‘/wp-admin/edit.php?post_type=job_listing’ ),’meta’ => array( ‘class’ => ‘jobroller_job_menu’,’title’ => __( ‘Jobs Menu’, ‘jraba’ ) ) ) );

    // all other links.. and then the count being last..

    $number_pages = wp_count_posts(‘job_listing’); $number_jobs = $number_pages->publish; echo $number_jobs;
    $jraba_count_job_listings = ‘ ‘ . $number_jobs . ‘ Jobs’;

    $wp_admin_bar->add_menu( array(
    ‘parent’ => ‘jobroller_job_links’,
    ‘id’ => ‘jobroller_job_count’,
    ‘title’ => $jraba_count_job_listings,
    ‘href’ => get_home_url( $blog->userblog_id, ‘/?s=&radius=1&location=’ ),
    ‘meta’ => array( ‘title’ => __( ‘Jobs Total’, ‘jraba’ ),’class’ => ‘jraba_count_job_listings’,’tabindex’ => -1, )
    ) );

    Your help would be greatly appreciated..

  2. * adds additional numbers between the div id=”wpcontent” and div id=”wpadminbar” class=”” role=”navigation”

    I’ve added a screenshot here: http:// jobortunity.ca/2121.png

    The numbers are 2121 as in 2 Jobs and 1 Resume, but for some reason is doubles..

Leave a Reply

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

%d bloggers like this: