[英]Can't get user post_count in WordPress using get_the_author_posts
I'm having troubles with getting a post count (total) for users. 我在为用户获取帖子数(总计)时遇到了麻烦。 I think it has to do the get_the_author_posts , which should give me the users total post - expressed as a number.
我认为它必须做get_the_author_posts ,这应该给我的用户总帖子 - 表示为数字。
function all_authors_list() {
$authors = get_users(array(
'role' => 'subscriber',
'orderby' => 'post_count',
'order' => 'DESC',
'number' => '20',
)
);
foreach($authors as $author) {
echo '<li class="author-name">' . $author->first_name . ' ' . $author->last_name . '</li>';
echo '<div class="author-post-count">' . $author->get_the_author_posts() . '</div>';
}
}
All of this works, except the author post count line. 除了作者发布计数行之外,所有这些都有效。
Any ideas? 有任何想法吗?
(thanks in advance :-) (提前致谢 :-)
Kindly try this one : 请试试这个:
echo '<div class="author-post-count">' . get_the_author_posts() . '</div>';
instead of 代替
echo '<div class="author-post-count">' . $author->get_the_author_posts() . '</div>';
And you can also try this one : 你也可以尝试这个:
echo '<div class="author-post-count">' . count_user_posts(your_author_id) . '</div>';
Hope this helps.. 希望这可以帮助..
You can use count_user_posts()
to get the post count for a user. 您可以使用
count_user_posts()
来获取用户的帖子计数。
See: http://codex.wordpress.org/Function_Reference/count_user_posts 请参阅: http : //codex.wordpress.org/Function_Reference/count_user_posts
In your case: 在你的情况下:
function all_authors_list() {
$authors = get_users(array(
'role' => 'subscriber',
'orderby' => 'post_count',
'order' => 'DESC',
'number' => '20',
)
);
foreach($authors as $author) {
echo '<li class="author-name">' . $author->first_name . ' ' . $author->last_name . '</li>';
echo '<div class="author-post-count">' . count_user_posts($author->ID) . '</div>';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.