Using get_user in wordpress with sorting

I have a table wp_users

that has a column ordering. I found out that it get_users()

returns all users.
I am using it as get_users('orderby=ordering')


I got the help form this link

But unfortunately this is not an ordinal sort. Any help?

+3


source to share


1 answer


You must first take a look at the users table from the database. The command you are trying is good, but the argument you are using for ordering might not be correct. You have to order a column from the users table like username or user id.

In the link you mentioned I found the following:

orderby - Sort by 'ID', 'login', 'nicename', 'email', 'url', 'registered', 'display_name' or 'post_count'.

order - ASC (ascending) or DESC (descending).

Some working examples:

Get users by nicename:



$users = get_users('orderby=nicename');

      

Other examples:

Display users sorted by post count, descending

$user_query = new WP_User_Query( array ( 'orderby' => 'post_count', 'order' => 'DESC' ) );

      

Show users sorted by registered, in ascending order

$user_query = new WP_User_Query( array ( 'orderby' => 'registered', 'order' => 'ASC' ) );

      

+2


source







All Articles