表示したいユーザーのidが決まっている場合。
<?php
$result = (int) $wpdb->get_var("
SELECT COUNT(*) FROM $wpdb->posts
WHERE post_type = 'post'
AND post_status = 'publish'
AND post_author = '1(ここにユーザーのidを入れる)'
");
?>
記事数:<?php echo $result; ?>BuddyPressのプロフィールページで表示したい場合。
<?php
$post_author = bp_displayed_user_id();
$result = (int) $wpdb->get_var("
SELECT COUNT(*) FROM $wpdb->posts
WHERE post_type = 'post'
AND post_status = 'publish'
AND post_author = $post_author
"); ?>
記事数:<?php echo $result; ?>

