Last active
August 29, 2015 13:56
-
-
Save lunaluna/9197044 to your computer and use it in GitHub Desktop.
【WordPress】カスタム投稿タイプの記事数をダッシュボードに表示
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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