Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I noticed recently my custom counts for custom post types are not showing on the dashboard. Im using this function:

right_now_content_table_end

It worked well before, Im not sure when it stopped working but I think after updating to 3.8?

Or is there a new function I should use with the new dashboard that is in 3.8?

Thanks in advance.

share|improve this question
add comment

3 Answers

The new action is dashboard_glance_items. It is a filter providing an array to which you can add items.

Example from my plugin T5 Taxonomy Location

add_filter(
    'dashboard_glance_items',
    array ( $this, 'add_to_glance' )
);


/**
 * Add locations to the new "At a glance" dashboard widget.
 *
 * @param  array $items
 * @return array
 */
public function add_to_glance( Array $items )
{
    $num  = wp_count_terms( $this->taxonomy );
    // Singular or Plural.
    $text = _n(
        '%s Location',
        '%s Locations',
        $num,
        'plugin_t5_tax_location'
    );
    // thousands separator etc.
    $text = sprintf( $text, number_format_i18n( $num ) );

    if ( current_user_can( "manage_$this->taxonomy" ) )
    {
        $url  = admin_url( "edit-tags.php?taxonomy=$this->taxonomy" );
        $text = "<a href='$url'>$text</a>";
    }

    $items[] = $text;

    return $items;
}

This change is not backwards compatible and rather … dirty. See ticket #26571 for problems and possible solutions.

share|improve this answer
    
Thanks for the asnwer, I checked but there is no codex reference created for this yet. Because I want to use it in a theme. –  Richard Mišenčík Dec 27 '13 at 14:25
add comment

The new thing is essentially different widget and that hook was removed from core. The closest replacement is new dashboard_glance_items filter.

See trac tickets:

share|improve this answer
add comment

Please check out this function. I believe it's temporary solution, but it works for me. More info can be found here: Add Custom Post Types and Taxonomies to At a Glance dashboard widget

add_action( 'dashboard_glance_items', 'cor_right_now_content_table_end' );
function cor_right_now_content_table_end() {
$args = array(
    'public' => true,
    '_builtin' => false
);
$output = 'object';
$operator = 'and';

$post_types = get_post_types( $args, $output, $operator );
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, intval( $num_posts->publish ) );
    if ( current_user_can( 'edit_posts' ) ) {
        $output = '<a href="edit.php?post_type=' . $post_type->name . '">' . $num . '&nbsp;' . $text . '</a>';
    }
    echo '<li class="post-count ' . $post_type->name . '-count">' . $output . '</li>';
}
$taxonomies = get_taxonomies( $args, $output, $operator );
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, intval( $num_terms ) );
    if ( current_user_can( 'manage_categories' ) ) {
        $output = '<a href="edit-tags.php?taxonomy=' . $taxonomy->name . '">' . $num . '&nbsp;' . $text . '</a>';
    }
    echo '<li class="taxonomy-count ' . $taxonomy->name . '-count">' . $output . '</li>';
}
}

// Add Some CSS to "At a Glance" Widget
function custom_colors() {
echo '<style type="text/css">
    .slides-count a:before {content:"\f233"!important}
    .gallery-count a:before {content:"\f163"!important}
    </style>';
}
add_action('admin_head', 'custom_colors');
share|improve this answer
    
Thanks alot, thats what I was looking for :) –  Richard Mišenčík Dec 28 '13 at 14:04
    
And what happens when a post type/taxonomy plugin adds its own items already? –  toscho Dec 28 '13 at 18:30
    
@toscho What do you mean? –  Richard Mišenčík Dec 28 '13 at 22:42
    
@RichardMišenčík My custom taxonomy would be listed twice. –  toscho Dec 29 '13 at 2:09
    
Well, i never said that it's all-in-one solution. It works perfectly on one of my websites which has 3 CPT and 4 taxonomies. –  Viktor Kovalenko Dec 29 '13 at 8:29
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.