0

I want to show users list but orderby with published post count in last month.

I have this code but doesn't work.

<?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 );
0

I presume you want to get the users who registered during the last month based on their post count.

Use the following code:

$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.
}
  • thank you, but no just user registered in last month, orderby post count in last month for whole users – davOOd Oct 6 '19 at 4:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.