Skip to content

Instantly share code, notes, and snippets.

@lunaluna
Last active August 29, 2015 13:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lunaluna/9197044 to your computer and use it in GitHub Desktop.
【WordPress】カスタム投稿タイプの記事数をダッシュボードに表示
<?php
// カスタム投稿タイプの記事数をダッシュボードに表示
add_filter( 'dashboard_glance_items', 'hoge_dashboard_glance_items' );
function hoge_dashboard_glance_items( $elements ) {
foreach ( array(
//'投稿タイプ名' を「,」区切りでココに記述。今回の場合は「お客様の声(voice)」と「商品登録(product)」。
'voice',
'product'
) as $post_type ) {
$name_posts = get_post_type_object( $post_type ) -> label;
$num_posts = wp_count_posts( $post_type );
if ( $num_posts && $num_posts -> publish ) {
$text = '【' .$name_posts. '】 ' .number_format_i18n( $num_posts -> publish ). '件の投稿';
$elements[] = sprintf( '<a href="edit.php?post_type=%1$s" class="%1$s-count">%2$s</a>', $post_type, $text );
}
}
return $elements;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment