Function Reference: geodir_posttype_link

Summary

Returns the post type link with parameters.

Global Values

$geodir_add_location_url
(bool) (required) If true it will add location name in url.

Default: None
$post
(object) (required) WordPress Post object.

Default: None
$gd_session
(object) (required) GeoDirectory Session object.

Default: None

Package

GeoDirectory

Parameters

$link
(string) (required) The post link.

Default: None
$post_type
(string) (required) The post type.

Default: None

Return Values

(string)
  • The modified link.

Change Log

Since: 1.0.0

1.5.5 Fixed post type archive link for selected location.

Source File

geodir_posttype_link() is located in geodirectory-functions/taxonomy_functions.php [Line: 1852]

Source Code

function geodir_posttype_link($link, $post_type) {
	global $geodir_add_location_url, $post, $gd_session;
	
	$location_terms = array();
	
	if (in_array($post_type, geodir_get_posttypes())) {
		if (get_option('geodir_add_location_url') && $gd_session->get('gd_multi_location') == 1) {
			if(geodir_is_page('detail') && !empty($post) && isset($post->country_slug)) {
                $location_terms = array(
                    'gd_country' => $post->country_slug,
                    'gd_region' => $post->region_slug,
                    'gd_city' => $post->city_slug
                );
            } else {
                $location_terms = geodir_get_current_location_terms('query_vars');
            }
			
			$location_terms = geodir_remove_location_terms($location_terms);
			
			if (!empty($location_terms)) {
				if (get_option('permalink_structure') != '') {
					$location_terms = implode("/", $location_terms);
					$location_terms = rtrim($location_terms, '/');
					
					$link .= urldecode($location_terms) . '/';
				} else {
					$link = geodir_getlink($link, $location_terms);
				}
			}
		}
	}
	
	return $link;
}