Skip to content

Instantly share code, notes, and snippets.

@slushman
Created April 15, 2015 03:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Get WordPress User By Metadata
/**
* Returns a list of user IDs matching the metavalue
* @param string $metakey The metadata key
* @param string $metavalue The value to find
* @return array|bool An array of user IDs or false
*/
function get_user_by_metadata( $metakey, $metavalue ) {
$return = array();
$args['fields'] = 'ID';
$args['meta_key'] = $metakey;
$args['meta_value'] = $metavalue;
$user_query = new WP_User_Query( $args );
if ( empty( $user_query->results ) ) { return FALSE; }
return $user_query;
} // get_user_by_metadata()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment