Created
August 18, 2017 05:05
-
-
Save waqasy/a0876094afe87e66eb70199ea5d6e4ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function find_lawyer( $country = '', $state = '', $city = '' ) { | |
$meta_query = array( | |
array( | |
'key' => 'user_locations', | |
'compare' => '!=', | |
'value' => '' | |
), | |
array( | |
'key' => 'is_published', | |
'compare' => '=', | |
'value' => '1' | |
), | |
); | |
if ( $country ) { | |
$meta_query[] = array( | |
'key' => 'user_locations', | |
'compare' => 'REGEXP', | |
'value' => '([\w|]*)country:' . $country . '([\w|]*)' | |
); | |
} | |
if ( $state ) { | |
$meta_query[] = array( | |
'key' => 'user_locations', | |
'compare' => 'REGEXP', | |
'value' => '([\w|]*)state:' . $state . '([\w|]*)' | |
); | |
} | |
if ( $city ) { | |
$meta_query[] = array( | |
'key' => 'user_locations', | |
'compare' => 'REGEXP', | |
'value' => '([\w|]*)city:' . $city . '([\w|]*)' | |
); | |
} | |
$users_query = new WP_User_Query( array( | |
'role' => 'lawyer', | |
'meta_query' => $meta_query | |
) ); | |
return $users_query->get_results(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment