Skip to content

Instantly share code, notes, and snippets.

@sunnyluthra
Last active October 8, 2015 06:39
Show Gist options
  • Save sunnyluthra/b25f8a5fe4d9915725df to your computer and use it in GitHub Desktop.
Save sunnyluthra/b25f8a5fe4d9915725df to your computer and use it in GitHub Desktop.
WordPress get user by metakey and value
<?php
function get_user_id_by_meta($key, $value) {
if (!$key && !$value) {
return false;
}
$args = array(
'meta_key' => $key,
'meta_value' => $value,
'fields' => 'ids',
'count_total' => false,
);
$user = get_users($args);
return current($user);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment