Ordering users of a specific role by last name

There is apparently an open ticket about this bug.

Here is a workaround that I tested:

$args  = array(
    'meta_key' => 'last_name',
    'role'     => 'guest-teacher'
);

$wp_user_query = new WP_User_Query($args);
$wp_user_query->query_orderby = str_replace( 'user_login', 'wp_usermeta.meta_value', $wp_user_query->query_orderby );
$wp_user_query->query();

$authors = $wp_user_query->get_results();

Problem with this is that it runs the query twice.

Leave a Comment