Skip to content

Instantly share code, notes, and snippets.

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
You can’t perform that action at this time.