i have a code
//first check if my_custom_users_list is defined before or not.
if(!function_exists('my_custom_users_list')){
//function that runs when shortcode is called
function my_custom_users_list() {
$args = array(); //define arguments if you need
$users = get_users($args);
$listHtml = '<ul>';
foreach($users as $user){
$listHtml .= '<li>'
. 'ID: '.$user->data->ID."<br />"
. 'Username: '.$user->data->user_login."<br />"
. 'Nice Name: '.$user->data->user_nicename."<br />"
. 'Display Name: '.$user->data->display_name."<br />"
. 'Email: '.$user->data->user_email."<br />"
. 'URL (website): '.$user->data->user_url."<br />"
. 'Registration Date: '.$user->data->user_registered."<br />"
. 'User Phone number: '.$user->data->billing_phone."<br />"
. '</li>';
}
$listHtml .= '</ul>';
return $listHtml;
}
}
//register my-users-list shortcode
function register_my_users_list_shortcode(){
add_shortcode('my-users-list', 'my_custom_users_list');
}
add_action( 'init', 'register_my_users_list_shortcode' );
//to test the shortcode, uncomment next line:
/*echo do_shortcode('[my-users-list]');*/
The code works, but not showing phone number I tried with meta phone_number also, but now showing.
You can get user info like ID, username etc. without using data inside your loop example: // Get User ID - you can use $user->ID // Get User Email - you can user $user->user_email
For your question about getting phone number you need to use get_user_meta function. If you use woocommerce and you want to get the billing phone number you can get it using this: get_user_meta($user->ID, 'billing_phone')