您是否正在使用WordPress 3.1+?有一个很好的get_users()
这个功能就可以了!然而,您需要一点魔法来引导:
add_action( \'pre_user_query\', \'wpse_11832_pre_user_query\' );
/**
* Adds "post_count" to the SELECT clause. Without this, the "post_count"
* property for users will be undefined.
*
* @param object $wp_user_query
*/
function wpse_11832_pre_user_query( $wp_user_query ) {
if ( $wp_user_query->query_vars[\'orderby\'] == \'post_count\' )
$wp_user_query->query_fields .= \', post_count\';
}
示例用法:
<?php foreach ( get_users( \'order=DESC&orderby=post_count&number=5\' ) as $user ) : ?>
<?php echo $user->display_name; ?> (<?php echo $user->post_count; ?> Posts)
<?php endforeach; ?>
Important: 您必须订购
post_count
, 否则将无法定义。