ファンクションへ
//ユーザーの投稿数を取得
function count_user_posttype($userid,$posttype) {
global $wpdb;
$where = get_posts_by_author_sql($posttype, true, $userid,true);
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
return $count;
}
//利用したい箇所に記述
//<?php echo count_user_posttype(get_the_author_meta('id'),"post"); ?/>
//ユーザー一覧に追加
function custom_users_columns( $columns ) {
$columns['user_shop'] = '登録数';
$columns['nickname'] = 'ニックネーム';
return $columns;
}
function custom_users_custom_column( $dummy, $column, $user_id ) {
if ( $column == 'user_shop' ) {
$user_info = count_user_posttype($user_id,"shop");
return $user_info;
}
if ( $column == 'nickname' ) {
$user_info = get_userdata($user_id);
return $user_info->nickname;
}
}
add_filter( 'manage_users_columns', 'custom_users_columns' );
add_filter( 'manage_users_custom_column', 'custom_users_custom_column', 10, 3 );
参考
管理画面のユーザー一覧に項目を加える方法
http://www.sandalot.com/%E7%AE%A1%E7%90%86%E7%94%BB%E9%9D%A2%E3%81%AE%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E4%B8%80%E8%A6%A7%E3%81%AB%E9%A0%85%E7%9B%AE%E3%82%92%E5%8A%A0%E3%81%88%E3%82%8B%E6%96%B9%E6%B3%95/
WordPressで指定ユーザーごとの投稿数を取得する
http://hirashimatakumi.com/blog/47.html
function count_user_posttype($userid,$posttype) {
global $wpdb;
$where = get_posts_by_author_sql($posttype, true, $userid,true);
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
return $count;
}
利用したい箇所に記述します。
<?php echo count_user_posttype(get_the_author_meta('id'),"post"); ?>
