I'm having a code, where it returns me some data from all users of the wp_usermeta
table, (in this case I'm just pulling the Full Name, and the Capabilities
, however to get my table fuller, add users email, which is in the wp_users
table, how can I make a query
that takes the values from both tables?
Here is the 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>';
}
?>