user6920400
user6920400

Reputation:

How to order user by registration date using WP_User_Query

I've to modify a query used in a Wordpress Theme because it's not orders users by their registration date. I need to shown last subscribed users. This query uses like ordering arg:

$args['orderby'] = 'rand'

What's it means?

I sobstituite this code row with

$args['orderby'] = 'user_registered'

but users shown aren't last subscribed users.

Can you help me, please? Thank's!

Upvotes: 1

Views: 2585

Answers (2)

Navnit Viradiya
Navnit Viradiya

Reputation: 81

Try this. It's working.

// define the pre_get_users callback 

function action_pre_user_query( $u_query ) { 

    $u_query->query_vars['orderby'] = 'user_registered';
    $u_query->query_vars['order'] = 'DESC';

}
add_action( 'pre_get_users', 'action_pre_user_query'); 

Upvotes: 2

Ahmed Elcheikh
Ahmed Elcheikh

Reputation: 586

$args['orderby'] = 'registered'  

try this

Upvotes: 0

Related Questions