Function Reference: geodir_get_current_location
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
Parameters
- $args
- (null) (required)
- Default: None
Return Values
- (string)
Source File
geodir_get_current_location() is located in geodir_location_manager/geodir_location_template_tags.php [Line: 130]
Source Code
function geodir_get_current_location($args = null) { global $geodir_location_names; $defaults = array( 'what' => '', 'location_text' => '', 'blank_location_text' => '', 'with_link' => false, 'link_traget' => '', 'container' => '' , 'container_class' => '' , 'switcher_link' => false, 'echo'=> true ); // location picker config arguments $c_l_config = wp_parse_args( $args, $defaults ); global $wpdb ; $order_by = ''; $location = ''; $what_lower = strtolower($c_l_config['what']) ; if( empty($location) && $c_l_config['what']=='') { if( empty($location) && isset($_SESSION['gd_multi_location']) ) { if(isset($_SESSION['gd_city']) && $_SESSION['gd_city'] != '') { if(isset($geodir_location_names['city']) && $geodir_location_names['city']){ $location = $geodir_location_names['city']; }else { $gd_city = $_SESSION['gd_city']; $loc_arr = $wpdb->get_row($wpdb->prepare("select city, region, country from " . POST_LOCATION_TABLE . " where city_slug=%s", array($gd_city))); $geodir_location_names['city'] = $loc_arr->city; $geodir_location_names['region'] = $loc_arr->region; $geodir_location_names['country'] = $loc_arr->country; $location = $loc_arr->city; } if($c_l_config['what']=='') $what_lower = 'city' ; } elseif(isset($_SESSION['gd_region']) && $_SESSION['gd_region']) { if(isset($geodir_location_names['region']) && $geodir_location_names['region']){ $location = $geodir_location_names['region']; }else { $gd_region = $_SESSION['gd_region']; $loc_arr = $wpdb->get_row($wpdb->prepare("select region, country from " . POST_LOCATION_TABLE . " where region_slug=%s ", array($gd_region))); $geodir_location_names['region'] = $loc_arr->region; $geodir_location_names['country'] = $loc_arr->country; $location = $loc_arr->region; } if($c_l_config['what']=='') $what_lower = 'region' ; } elseif(isset($_SESSION['gd_country']) && $_SESSION['gd_country']) { if(isset($geodir_location_names['country']) && $geodir_location_names['country']){ $location = $geodir_location_names['country']; }else { $gd_country = $_SESSION['gd_country']; $location = $wpdb->get_var($wpdb->prepare("select country from " . POST_LOCATION_TABLE . " where country_slug=%s ", array($gd_country))); $geodir_location_names['country'] = $location; } if($c_l_config['what']=='') $what_lower = 'country'; } } } if( empty($location) && isset($_SESSION['gd_multi_location']) ) { if(isset($_SESSION['gd_' .$what_lower ]) && $_SESSION['gd_'.$what_lower ] != '') { $gd_location = $_SESSION['gd_' .$what_lower ]; if(isset($geodir_location_names[$what_lower]) && $geodir_location_names[$what_lower]){ $location = $geodir_location_names[$what_lower]; }else { $loc_arr = $wpdb->get_row($wpdb->prepare("select city, region, country from " . POST_LOCATION_TABLE . " where " . $what_lower . "_slug=%s", array($gd_location))); if($what_lower=='city'){ $geodir_location_names['city'] = $loc_arr->city;} if($what_lower=='region'){$geodir_location_names['region'] = $loc_arr->region;} if($what_lower=='country'){$geodir_location_names['country'] = $loc_arr->country;} $location = $geodir_location_names[$what_lower]; } } } if($location!='' && $c_l_config['location_text'] != '') $location = $c_l_config['location_text'] ; else if($location=='') $location = $c_l_config['blank_location_text'] ; $location_link = '' ; $link_a_tag_start = '' ; $link_a_tag_end = ''; $base_location= geodir_get_location_link('base'); if($c_l_config['with_link']) { $location_link = $base_location; $locations = array(); if($what_lower=='city') { //if(get_option('geodir_show_location_url') == 'all') { if(isset($_SESSION['gd_country']) && $_SESSION['gd_country']!='') $locations['gd_country'] = $_SESSION['gd_country']; if(isset($_SESSION['gd_region']) && $_SESSION['gd_region']!='') $locations['gd_region'] = $_SESSION['gd_region']; } if(isset($_SESSION['gd_city']) && $_SESSION['gd_city']!='') $locations['gd_city'] = $_SESSION['gd_city']; } if($what_lower=='region' && get_option('geodir_show_location_url') == 'all' ) { if(isset($_SESSION['gd_country']) && $_SESSION['gd_country']!='') $locations['gd_country'] = $_SESSION['gd_country']; if(isset($_SESSION['gd_region'])&& $_SESSION['gd_region']!='') $locations['gd_region'] = $_SESSION['gd_region']; } if($what_lower=='country' && get_option('geodir_show_location_url') == 'all') { if(isset($_SESSION['gd_country']) && $_SESSION['gd_country']!='') $locations['gd_country'] = $_SESSION['gd_country']; } //print_r($locations) ; foreach($locations as $key => $location) { if ( get_option('permalink_structure') != '' ) $location_link .= $location; else $location_link .= '&'.$key.'='.$location; } $location_link = geodir_location_permalink_url( $location_link ); if($c_l_config['link_traget'] != '') $link_traget = " target="".$link_traget."" " ; $link_a_tag_start = "" ; $link_a_tag_end = "" ; } if($location!='') $location_with_link = $link_a_tag_start.$location.$link_a_tag_end; else $location_with_link = ''; if($c_l_config['container'] != '') $location_with_link = "<" . $c_l_config['container'] . " class='" . $c_l_config['container_class'] . "' >". $location_with_link ; if($c_l_config['switcher_link']) { $location_with_link .= " "; } if($c_l_config['container'] != '') $location_with_link .= "" . $c_l_config['container'] . ">" ; if($c_l_config['echo']) echo $location_with_link ; else return $location_with_link ; }