Guest User

Untitled

a guest
Nov 14th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. $args = array(
  2. 'role' => 'agent',
  3. 'orderby' => 'user_nicename',
  4. 'order' => 'ASC'
  5. );
  6.  
  7. $agent_users = get_users($args);
  8.  
  9. <option value="0">Select Agent</option>
  10.  
  11. foreach ($agent_users as $user){
  12. $user_info = get_userdata($user->ID);
  13. $username = $user_info->user_login; // this gives perfect data, checked using print_r
  14. $first_name = $user_info->first_name;
  15. $last_name = $user_info->last_name;
  16. $name = $first_name . ' ' . $last_name;
  17.  
  18. // here i am stucked, if first name and last name is not set, then use user login in $agent_filter_name var.
  19. if (!empty($name)) {
  20. $agent_filter_name = $name;
  21. } else {
  22. $agent_filter_name = $username;
  23. }
  24.  
  25. <option value=<?php echo $user->user_email; ?>>
  26. <?php echo $agent_filter_name; ?>
  27. </option>
  28.  
  29. // this will output like this
  30. 1) abc
  31. 2) xyz
  32. 3) .... (blank while first name or last name is empty, here we want user name)
  33. 4) pqr
  34. }
  35. }
Add Comment
Please, Sign In to add comment