How can I list users by last name ASC when using WP_User_Query?
There is an orderby parameter but looking in core it doesn’t accept ordering my user meta. Anyone know how to extend WP to allow this ordering by last name?
How can I list users by last name ASC when using WP_User_Query?
There is an orderby parameter but looking in core it doesn’t accept ordering my user meta. Anyone know how to extend WP to allow this ordering by last name?
You must be logged in to post a comment.
There is a better way to do this as of WordPress version 3.7. Use the WordPress property meta_key to select the last name property and then orderby => meta_value with an ascending order.
Made something myself:
Page template file:
Just so you are aware I’m using an alpha version of WP-PageNavi that supports pagination for WP_User_Query. The above just deals with layout and pagination. Below is where the magic happens:
functions.php file:
The above query is not efficient and would be terribly slow on large user base. In my case I’m running on 250 users max. There would be better ways of doing this but I wanted to maintain pagination with WP-PageNavi.
Filter the string
'query'
and change theORDER BY
part. See https://gist.github.com/1281778#L160 for an example.