[wp-trac] [WordPress Trac] #44409: get_userdata and get_user_field_by
WordPress Trac
noreply at wordpress.org
Wed Jun 20 09:08:26 UTC 2018
#44409: get_userdata and get_user_field_by
--------------------------+-----------------------------
Reporter: markuscode | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Hi last time I ask about the get_user_field, on the ticket #44392.
I ask not about usermeta, I ask about users table. How can get just
user_email by user ID without selecting all information, just user_email.
Always I do for myself something like that:
{{{#!php
<?php
if(!function_exists('get_user_field_by')){
/**
* Gets the user field by.
*
* @param string $fuild The fuild
* @param array $where The where
*/
function get_user_field_by($fuild = "",$where = array()){
global $wpdb;
$sql = "SELECT ".$fuild." FROM {$wpdb->prefix}users";
$wherecount = 0;
foreach ($where as $key => $value) {
if($wherecount == 0){
$sql .= " WHERE $key = '$value'";
}else{
$sql .= " AND $key = '$value'";
}
}
$wherecount++;
$results = $wpdb->get_results( $sql , OBJECT );
if(!empty($results)){
$results = reset($results);
}
return $results;
}
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44409>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list