获得至少一篇帖子的用户

时间:2011-10-21 作者:Dogbert

我怎样才能让所有用户至少有一篇帖子?我认为这是不可能的get_users 作用

1 个回复
最合适的回答,由SO网友:EarnestoDev 整理而成

global $wpdb;
$min_posts = 5; // Make sure it\'s int, it\'s not escaped in the query
$author_ids = $wpdb->get_col("SELECT `post_author` FROM
    (SELECT `post_author`, COUNT(*) AS `count` FROM {$wpdb->posts}
        WHERE `post_status`=\'publish\' GROUP BY `post_author`) AS `stats`
    WHERE `count` >= {$min_posts} ORDER BY `count` DESC;");
// Do what you want to $author_ids from here on...
这将返回User IDs 在发表了5篇以上帖子的作者中,按帖子数量降序排列。

结束