1
I have a code, where it returns me some data of all users of the table wp_usermeta
, ( in case I’m only pulling the full Name, and the Capabilities
, but to get more complete my table, I would like to add the users email, which is in the table wp_users
, how can I make a query
to take the values of both tables?
Follows code:
<?php
global $wpdb;
$sql = "
SELECT user_id,meta_key,meta_value
FROM {$wpdb->usermeta}
WHERE ({$wpdb->usermeta}.meta_key = 'first_name' OR {$wpdb->usermeta}.meta_key = 'last_name' OR {$wpdb->usermeta}.meta_key = 'wp_capabilities')";
$ansatte = $wpdb->get_results($sql);
$users = array();
foreach ($ansatte as $a) {
$users[$a->user_id][$a->meta_key] = $a->meta_value;
}
foreach ($users as $u) {
echo $u['first_name'].' '.$u['last_name'].' '.$u['wp_capabilities'].'<br>';
}
?>