功能count_user_posts
只接受用户ID,因此从不考虑您的参数。下面是一个简单的函数,用于按状态获取计数
function count_user_posts_by_status($post_status = \'publish\',$user_id = 0){
global $wpdb;
$count = $wpdb->get_var(
$wpdb->prepare(
"
SELECT COUNT(ID) FROM $wpdb->posts
WHERE post_status = %s
AND post_author = %d",
$post_status,
$user_id
)
);
return ($count) ? $count : 0;
}
用法:
<?php echo count_user_posts_by_status(\'draft\',$userID); ?>