Function Reference: geodir_get_locations
Summary
Get locations by keyword.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
Package
GeoDirectory_Location_Manager
Parameters
- $term
- (string) (required) Search type. Possible values are ‘country’, ‘region’, ‘city’.
- Default: None
- $search
- (string) (required) Keyword.
- Default: None
- $single
- (bool) (required) Return only single row? Default: false.
- Default: None
Return Values
- (bool|mixed)
Change Log
Since: 1.0.0
Source File
geodir_get_locations() is located in geodir_location_manager/geodir_location_functions.php [Line: 2091]
Source Code
function geodir_get_locations($term = '', $search = '', $single = false) { global $wpdb; $where = $group_by = ''; $where_array = array(); switch($term): case 'country': if($search !='' ){ $where = $wpdb->prepare(" AND ( country = %s OR country_slug = %s )", array($search,$search)); }else{ $group_by = " GROUP BY country ";} break; case 'region': if($search !='' ){ $where = $wpdb->prepare(" AND ( region = %s OR region_slug = %s ) ", array($search,$search)); }else{ $group_by = " GROUP BY region ";} break; case 'city': if($search !='' ){ $where = $wpdb->prepare(" AND ( city = %s OR city_slug = %s ) ", array($search,$search)); }else{ $group_by = " GROUP BY city ";} break; endswitch; $locations = $wpdb->get_results( "SELECT * FROM ".POST_LOCATION_TABLE." WHERE 1=1 ".$where.$group_by." ORDER BY city " ); return (!empty($locations)) ? $locations : false; }