Created
April 15, 2015 03:14
-
-
Save slushman/f236ae998f7b5cd7a49c to your computer and use it in GitHub Desktop.
Get WordPress User By Metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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