Function Reference: geodir_listing_rewrite_rules
Summary
Get the full set of generated rewrite rules.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
Parameters
- $rules
- (array) (required) The compiled array of rewrite rules.
- Default: None
Return Values
- (array)
- Rewrite rules.
Change Log
Since: 1.0.0
1.5.4 Modified to add country/city & region/city rules.
1.5.7 Modified to manage neighbourhood permalinks.
Source File
geodir_listing_rewrite_rules() is located in geodirectory-functions/custom_taxonomy_hooks_actions.php [Line: 194]
Source Code
function geodir_listing_rewrite_rules($rules) { $newrules = array(); $taxonomies = get_option('geodir_taxonomies'); $detail_url_seprator = get_option('geodir_detailurl_separator'); // create rules for post listing if (is_array($taxonomies)): foreach ($taxonomies as $taxonomy => $args): $post_type = $args['object_type']; $listing_slug = $args['listing_slug']; if (strpos($taxonomy, 'tags')) { $newrules[$listing_slug . '/(.+?)/page/?([0-9]{1,})/?$'] = 'index.php?' . $taxonomy . '=$matches[1]&paged=$matches[2]'; $newrules[$listing_slug . '/(.+?)/?$'] = 'index.php?' . $taxonomy . '=$matches[1]'; } else { // use this loop to add paging for details page comments paging $newrules[str_replace("/tags","",$listing_slug) . '/(.+?)/comment-page-([0-9]{1,})/?$'] = 'index.php?' . $taxonomy . '=$matches[1]&cpage=$matches[2]'; } endforeach; endif; // create rules for location listing $location_page = get_option('geodir_location_page'); if($location_page) { global $wpdb; $location_prefix = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_type='page' AND ID=%d", $location_page)); } if (!isset($location_prefix)) $location_prefix = 'location'; $location_manager = function_exists('geodir_location_plugin_activated') ? true : false; // Check location manager installed & active. if ($location_manager) { $hide_country_part = get_option('geodir_location_hide_country_part'); $hide_region_part = get_option('geodir_location_hide_region_part'); } $neighbourhood_active = $location_manager && get_option('location_neighbourhoods') ? true : false; if ($location_manager && ($hide_country_part || $hide_region_part)) { $matches2 = ''; $matches1 = ''; if (!$hide_country_part && $hide_region_part) { // country/city $matches1 = 'gd_country'; $matches2 = 'gd_city'; } else if ($hide_country_part && !$hide_region_part) { // region/city $matches1 = 'gd_region'; $matches2 = 'gd_city'; } else { // city $matches1 = 'gd_city'; } if ($matches2) { if ($neighbourhood_active) { $newrules[$location_prefix . '/([^/]+)/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $location_page . '&' . $matches1 . '=$matches[1]&' . $matches2 . '=$matches[2]&gd_neighbourhood=$matches[3]'; } $newrules[$location_prefix . '/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $location_page . '&' . $matches1 . '=$matches[1]&' . $matches2 . '=$matches[2]'; } else { if ($neighbourhood_active) { $newrules[$location_prefix . '/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $location_page . '&' . $matches1 . '=$matches[1]&gd_neighbourhood=$matches[2]'; } } $newrules[$location_prefix . '/([^/]+)/?$'] = 'index.php?page_id=' . $location_page . '&' . $matches1 . '=$matches[1]'; } else { // country/region/city if ($neighbourhood_active) { $newrules[$location_prefix . '/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $location_page . '&gd_country=$matches[1]&gd_region=$matches[2]&gd_city=$matches[3]&gd_neighbourhood=$matches[4]'; } $newrules[$location_prefix . '/([^/]+)/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $location_page . '&gd_country=$matches[1]&gd_region=$matches[2]&gd_city=$matches[3]'; $newrules[$location_prefix . '/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $location_page . '&gd_country=$matches[1]&gd_region=$matches[2]'; $newrules[$location_prefix . '/([^/]+)/?$'] = 'index.php?page_id=' . $location_page . '&gd_country=$matches[1]'; } if ($location_page && geodir_is_wpml()) { foreach(icl_get_languages('skip_missing=N') as $lang){ $alt_page_id = ''; $alt_page_id = geodir_wpml_object_id($location_page, 'page', false,$lang['language_code']); if($alt_page_id){ $location_prefix = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_type='page' AND ID=%d", $alt_page_id)); if ($location_manager && ($hide_country_part || $hide_region_part)) { $matches2 = ''; $matches1 = ''; if (!$hide_country_part && $hide_region_part) { // country/city $matches1 = 'gd_country'; $matches2 = 'gd_city'; } else if ($hide_country_part && !$hide_region_part) { // region/city $matches1 = 'gd_region'; $matches2 = 'gd_city'; } else { // city $matches1 = 'gd_city'; } if ($matches2) { if ($neighbourhood_active) { $newrules[$location_prefix . '/([^/]+)/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $alt_page_id . '&' . $matches1 . '=$matches[1]&' . $matches2 . '=$matches[2]&gd_neighbourhood=$matches[3]'; } $newrules[$location_prefix . '/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $alt_page_id . '&' . $matches1 . '=$matches[1]&' . $matches2 . '=$matches[2]'; } else { if ($neighbourhood_active) { $newrules[$location_prefix . '/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $alt_page_id . '&' . $matches1 . '=$matches[1]&gd_neighbourhood=$matches[2]'; } } $newrules[$location_prefix . '/([^/]+)/?$'] = 'index.php?page_id=' . $alt_page_id . '&' . $matches1 . '=$matches[1]'; } else { // country/region/city if ($neighbourhood_active) { $newrules[$location_prefix . '/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $alt_page_id . '&gd_country=$matches[1]&gd_region=$matches[2]&gd_city=$matches[3]&gd_neighbourhood=$matches[4]'; } $newrules[$location_prefix . '/([^/]+)/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $alt_page_id . '&gd_country=$matches[1]&gd_region=$matches[2]&gd_city=$matches[3]'; $newrules[$location_prefix . '/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $alt_page_id . '&gd_country=$matches[1]&gd_region=$matches[2]'; $newrules[$location_prefix . '/([^/]+)/?$'] = 'index.php?page_id=' . $alt_page_id . '&gd_country=$matches[1]'; } } } } $newrules[$location_prefix . '/?$'] = 'index.php?page_id=' . $location_page; $rules = array_merge($newrules, $rules); return $rules; }