--- original/delta/item.php +++ patch/delta/item.php @@ -125,7 +125,24 @@ } } - $link_array = array('page' => 'search', 'sCategory' => osc_item_category_id(), 'sCountry' => osc_item_country_code(), 'sRegion' => osc_item_region_id(), 'sCity' => osc_item_city_id()); + $link_array = array('page' => 'search'); + $seo_item_category_id = (int) osc_item_category_id(); + $seo_item_city_id = (int) osc_item_city_id(); + $seo_item_region_id = (int) osc_item_region_id(); + $seo_item_country_code = trim((string) osc_item_country_code()); + + if ($seo_item_category_id > 0) { + $link_array['sCategory'] = $seo_item_category_id; + } + + // A city ID already identifies its region and country. Do not duplicate them in the URL. + if ($seo_item_city_id > 0) { + $link_array['sCity'] = $seo_item_city_id; + } elseif ($seo_item_region_id > 0) { + $link_array['sRegion'] = $seo_item_region_id; + } elseif ($seo_item_country_code !== '') { + $link_array['sCountry'] = $seo_item_country_code; + } $active_listing = __('active listing', 'delta'); $active_listings = __('active listings', 'delta');