Skip to content

Instantly share code, notes, and snippets.

@vc27
Created December 12, 2011 21:36
Show Gist options
  • Save vc27/1469220 to your computer and use it in GitHub Desktop.
Save vc27/1469220 to your computer and use it in GitHub Desktop.
Get a users id from meta_key and meta_value
/**
* Get User Id from meta_key, meta_value
**/
function get_user_id_by_meta( $meta_key, $meta_value ) {
global $wpdb;
$querystr = "SELECT $wpdb->usermeta.user_id FROM $wpdb->usermeta WHERE $wpdb->usermeta.meta_key = '$meta_key' AND $wpdb->usermeta.meta_value = '$meta_value'";
$results = $wpdb->get_results( $querystr, ARRAY_N );
if ( is_numeric( $results[0][0] ) AND $results[0][0] > 0 )
return $results[0][0];
else
return false;
} // end function get_user_id_by_meta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment