Skip to content

Instantly share code, notes, and snippets.

@slushman
Created April 15, 2015 03:14
Show Gist options
  • Save slushman/f236ae998f7b5cd7a49c to your computer and use it in GitHub Desktop.
Save slushman/f236ae998f7b5cd7a49c to your computer and use it in GitHub Desktop.
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