Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created August 15, 2012 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpsmith/3361816 to your computer and use it in GitHub Desktop.
Save wpsmith/3361816 to your computer and use it in GitHub Desktop.
Orderby meta_value last_name via WP_User_Query Object
<?php
// Caveat: This creates 2 queries and any use of this code should also use site transients
// prepare arguments
$args = array(
'meta_key' => 'last_name',
);
// Create the WP_User_Query object
$author_query = new WP_User_Query( $args );
// Modify the WP_User_Query object
$author_query->query_orderby = str_replace( 'user_login', 'wpsand_usermeta.meta_value', $author_query->query_orderby );
// Re-query
$author_query->query();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment