该查询按上个月发布帖子计数显示用户列表排序

时间:2019-10-05 作者:davOOd

我想显示用户列表,但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 );

1 个回复
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.
}

相关推荐

使用新的WP-Query()从循环中过滤后期格式;

嗨,我目前正在为我的博客构建一个主题。下面的代码指向最新的帖子(特色帖子)。因为这将有一个不同的风格比所有其他职位。然而我想过滤掉帖子格式:链接使用我在循环中定义的WP查询,因为它给我带来了更多的灵活性。我该怎么做呢? <?php $featured = new WP_Query(); $featured->query(\'showposts=1\'); ?> <?php while ($featured->have_post