您可以创建一个易于使用的函数来实现这一点。
像这样:
<?php
function sg_user_posts_by_type($userid, $post_status) {
$args = array(
\'numberposts\' => -1,
\'post_status\' => array($post_status),
\'author\' => $userid
);
$count_posts = count(get_posts($args));
return $count_posts;
}
if (is_user_logged_in()) {
// GET CURRENT USER DATA
$user_id = get_current_user_id();
$user_data = get_userdata($user_id);
$publish_count = sg_user_posts_by_type($user_id, \'publish\');
$pending_count = sg_user_posts_by_type($user_id, \'pending\');
$draft_count = sg_user_posts_by_type($user_id, \'draft\');
echo \'
<h3>Hey \'.$user_data->last_name.\', You got:</h3>
<ul>
<li>\'.$publish_count.\' published Posts</li>
<li>\'.$pending_count.\' pending Posts</li>
<li>\'.$draft_count.\' drafts</li>
</ul>
\';
}
?>
如果需要,您可以降低资源成本,但这应该可以很好地工作
希望这有帮助;)