## Query both first_name and last_name from wp_usermeta at the same time

Question

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?

0
8 months 2020-12-08T11:10:19-05:00 0 Answers 6 views 0