我想显示用户列表,但orderby
上个月发布的帖子数量。
我有这个代码,但不起作用。
<?php
$args = array(
\'orderby\' => \'post_count\',
\'order\' => \'DESC\',
\'role\' => \'Subscriber\',
\'number\' => \'4\',
\'date_query\' => array(
array(
\'after\' => \'12 hours ago\',
\'inclusive\' => true,
),
),
);
$user_query = new WP_User_Query( $args );
SO网友:Anteraez
我假设您希望根据帖子数量获取上个月注册的用户。
使用以下代码:
$args = array(
\'orderby\' => \'post_count\', // Gets the users based on the no. of posts they have made.
\'order\' => \'DESC\',
\'role\' => \'Subscriber\', // Gets the users with this role.
\'number\' => 4, // Total no. of users that the query outputs.
\'date_query\' => array(
array(
\'after\' => \'1 month ago\', // Gets the users registered during the last month.
\'inclusive\' => true,
)
),
);
$users = new WP_User_Query($args);
foreach( $users as $user ) {
echo $user->display_name . \'<br>\'; // Outputs the user\'s display name on a new line.
}