Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. function find_lawyer( $country = '', $state = '', $city = '' ) {
  2.  
  3. $meta_query = array(
  4. array(
  5. 'key' => 'user_locations',
  6. 'compare' => '!=',
  7. 'value' => ''
  8. ),
  9. array(
  10. 'key' => 'is_published',
  11. 'compare' => '=',
  12. 'value' => '1'
  13. ),
  14. );
  15.  
  16. if ( $country ) {
  17. $meta_query[] = array(
  18. 'key' => 'user_locations',
  19. 'compare' => 'REGEXP',
  20. 'value' => '([\w|]*)country:' . $country . '([\w|]*)'
  21. );
  22. }
  23.  
  24. if ( $state ) {
  25. $meta_query[] = array(
  26. 'key' => 'user_locations',
  27. 'compare' => 'REGEXP',
  28. 'value' => '([\w|]*)state:' . $state . '([\w|]*)'
  29. );
  30. }
  31.  
  32. if ( $city ) {
  33. $meta_query[] = array(
  34. 'key' => 'user_locations',
  35. 'compare' => 'REGEXP',
  36. 'value' => '([\w|]*)city:' . $city . '([\w|]*)'
  37. );
  38. }
  39.  
  40. $users_query = new WP_User_Query( array(
  41. 'role' => 'lawyer',
  42. 'meta_query' => $meta_query
  43. ) );
  44.  
  45.  
  46. return $users_query->get_results();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement