Skip to content

Instantly share code, notes, and snippets.

@waqasy
Created August 18, 2017 05:05
Show Gist options
  • Save waqasy/a0876094afe87e66eb70199ea5d6e4ba to your computer and use it in GitHub Desktop.
Save waqasy/a0876094afe87e66eb70199ea5d6e4ba to your computer and use it in GitHub Desktop.
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