Add Custom Post Type Counts to the Dashboard

we have several ways to add custom post type counts to the dashboard including right_now_content_table_end.

For Example:

function add_area_counts() {
if (!post_type_exists(‘escorts’)) {
return;
}

$num_posts = wp_count_posts( ‘escorts’ );
$num = number_format_i18n( $num_posts->publish );
$text = _n( ‘Areas’, ‘Areas’, intval($num_posts->publish) );
if ( current_user_can( ‘edit_posts’ ) ) {
$num = “<a href=’edit.php?post_type=areas’>$num</a>”;
$text = “<a href=’edit.php?post_type=areas’>$text</a>”;
}
echo ‘<td>’ . $num . ‘</td>’;
echo ‘<td>’ . $text . ‘</td>’;

echo ‘</tr>’;

if ($num_posts->pending > 0) {
$num = number_format_i18n( $num_posts->pending );
$text = _n( ‘Areas Pending’, ‘Areas Pending’, intval($num_posts->pending) );
if ( current_user_can( ‘edit_posts’ ) ) {
$num = “<a href=’edit.php?post_status=pending&post_type=recipes’>$num</a>”;
$text = “<a href=’edit.php?post_status=pending&post_type=recipes’>$text</a>”;
}
echo ‘<td>’ . $num . ‘</td>’;
echo ‘<td>’ . $text . ‘</td>’;

echo ‘</tr>’;
}
}
add_action( ‘right_now_content_table_end’, ‘add_area_counts’ );

To get more information click here

Share This Post

Post Comment