Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $args = array(
- 'role' => 'agent',
- 'orderby' => 'user_nicename',
- 'order' => 'ASC'
- );
- $agent_users = get_users($args);
- <option value="0">Select Agent</option>
- foreach ($agent_users as $user){
- $user_info = get_userdata($user->ID);
- $username = $user_info->user_login; // this gives perfect data, checked using print_r
- $first_name = $user_info->first_name;
- $last_name = $user_info->last_name;
- $name = $first_name . ' ' . $last_name;
- // here i am stucked, if first name and last name is not set, then use user login in $agent_filter_name var.
- if (!empty($name)) {
- $agent_filter_name = $name;
- } else {
- $agent_filter_name = $username;
- }
- <option value=<?php echo $user->user_email; ?>>
- <?php echo $agent_filter_name; ?>
- </option>
- // this will output like this
- 1) abc
- 2) xyz
- 3) .... (blank while first name or last name is empty, here we want user name)
- 4) pqr
- }
- }
Add Comment
Please, Sign In to add comment