WordPress - 仅显示作者的帖子

时间:2012-01-11 21:57:55

标签: wordpress

我正在尝试列出我的wordpress博客中已发布帖子的所有作者,不包括管理员。以下工作用于排除管理员,但是当我添加“AND post_count> 0”以仅显示具有帖子的作者时,它不会显示任何内容。有没有办法修改此代码只显示有帖子的作者?

function contributors() { 
global $wpdb;
$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> 'admin' AND post_count > 0 ORDER BY display_name");

foreach ($authors as $author ) {

echo "<li>";
echo "<a href=\"".get_bloginfo('url')."/author/";
the_author_meta('user_nicename', $author->ID);
echo "/\">";
echo get_avatar($author->ID, 12);
echo "</a>";
echo "<a href=\"".get_bloginfo('url')."/author/";
the_author_meta('user_nicename', $author->ID);
echo "/\">";
the_author_meta('display_name', $author->ID);
echo "</a>";
echo "</li>";
}
}

1 个答案:

答案 0 :(得分:1)

尝试使用此查询

SELECT * FROM (SELECT ID, 
    user_nicename, 
    (select count(*) from wp_posts where post_author=w.ID) as posts 
FROM wp_users w 
WHERE display_name <> 'admin' 
ORDER BY display_name) as final WHERE posts>0