Function Reference: geodir_get_current_location_terms
Summary
Returns current location terms.
Global Values
- $wp
- (object) (required) WordPress object.
- Default: None
- $gd_session
- (object) (required) GeoDirectory Session object.
- Default: None
Package
GeoDirectory
Parameters
- $location_array_from
- (string) (required) Place to look for location array.
- Default: : ‘session’
- $gd_post_type
- (string) (required) The post type.
- Default: None
Return Values
- (array)
- The location term array.
Change Log
Since: 1.0.0
Filters
‘geodir_current_location_terms’ [Line: 392]
Source File
geodir_get_current_location_terms() is located in geodirectory-functions/location_functions.php [Line: 328]
Source Code
function geodir_get_current_location_terms($location_array_from = 'session', $gd_post_type = '')
{
global $wp, $gd_session;
$location_array = array();
if ($location_array_from == 'session') {
if ($gd_session->get('gd_country') == 'me' || $gd_session->get('gd_region') == 'me' || $gd_session->get('gd_city') == 'me') {
return $location_array;
}
$country = isset($_REQUEST['gd_country']) ? $_REQUEST['gd_country'] : $gd_session->get('gd_country');
if ($country != '' && $country)
$location_array['gd_country'] = urldecode($country);
$region = isset($_REQUEST['gd_region']) ? $_REQUEST['gd_region'] : $gd_session->get('gd_region');
if ($region != '' && $region)
$location_array['gd_region'] = urldecode($region);
$city = isset($_REQUEST['gd_city']) ? $_REQUEST['gd_city'] : $gd_session->get('gd_city');
if ($city != '' && $city)
$location_array['gd_city'] = urldecode($city);
} else {
if ((isset($wp->query_vars['gd_country']) && $wp->query_vars['gd_country'] == 'me') || (isset($wp->query_vars['gd_region']) && $wp->query_vars['gd_region'] == 'me') || (isset($wp->query_vars['gd_city']) && $wp->query_vars['gd_city'] == 'me')) {
return $location_array;
}
$country = (isset($wp->query_vars['gd_country']) && $wp->query_vars['gd_country'] != '') ? $wp->query_vars['gd_country'] : '';
$region = (isset($wp->query_vars['gd_region']) && $wp->query_vars['gd_region'] != '') ? $wp->query_vars['gd_region'] : '';
$city = (isset($wp->query_vars['gd_city']) && $wp->query_vars['gd_city'] != '') ? $wp->query_vars['gd_city'] : '';
if ($country != '')
$location_array['gd_country'] = urldecode($country);
if ($region != '')
$location_array['gd_region'] = urldecode($region);
if ($city != '')
$location_array['gd_city'] = urldecode($city);
// Fix category link in ajax popular category widget on change post type
if (empty($location_array) && defined('DOING_AJAX') && DOING_AJAX) {
$location_array = geodir_get_current_location_terms('session');
}
}
/**
* Filter the location terms.
*
* @since 1.4.6
* @package GeoDirectory
*
* @param array $location_array {
* Attributes of the location_array.
*
* @type string $gd_country The country slug.
* @type string $gd_region The region slug.
* @type string $gd_city The city slug.
*
* }
* @param string $location_array_from Source type of location terms. Default session.
* @param string $gd_post_type WP post type.
*/
$location_array = apply_filters( 'geodir_current_location_terms', $location_array, $location_array_from, $gd_post_type );
return $location_array;
}