I'm trying to fetch both the first_name and last_name of all users at the same time, using the wpdb-object and the wp_usermeta table. I can't seem to figure out how to get both in the same query. Below is what I've got so far.
global $wpdb;
$ansatte = $wpdb->get_results("SELECT user_id, meta_value AS first_name FROM wp_usermeta WHERE meta_key='first_name'");
foreach ($ansatte as $ansatte) {
echo $ansatte->first_name;
}
Using the above code I'm able to echo out the first names of all users, but i would like for the last_name to be available aswell, like so;
foreach ($ansatte as $ansatte) {
echo $ansatte->first_name . ' ' $ansatte->last_name;
}
Any ideas?
$wpdb
object, else you risk compatability issues across sites and multisite installs