I am trying to get custom meta data from all users. I have the following code the returns no errors. So I don’t know what is going wrong. Is there a more simple way to loop over all id’s and return custom meta data?
global $wpdb;
$wp_user_search = $wpdb->get_results("SELECT ID FROM $wpdb->users ORDER BY ID");
foreach ($wp_user_search as $userid) {
$all_meta_for_user = get_user_meta($userid->id);
$email_alert = $all_meta_for_user['email_sms'][0];
echo $email_alert;
}
Use regular WordPress functions.
In this case,
get_users()
.Like this:
Also note that you were using
$userid->id
, instead of$userid->ID
.For checking the values of your variables use:
var_dump($userid)
echo '<pre>' . print_r( $all_meta_for_user, true ) . '</pre>';