Function Reference: geodir_listing_permalink_structure
Summary
Returns permalink structure using post link.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
- $plugin_prefix
- (string) (required) Geodirectory plugin table prefix.
- Default: None
- $wp_query
- (object) (required) WordPress Query object.
- Default: None
- $post
- (object) (required) WordPress Post object.
- Default: None
Package
GeoDirectory
Parameters
- $post_link
- (string) (required) The post link.
- Default: None
- $post_obj
- (object) (required) The post object.
- Default: None
- $leavename
- (string) (required) Not yet implemented.
- Default: None
- $sample
- (bool) (required) Is this a sample post?.
- Default: None
Return Values
- (string)
- The post link.
Change Log
Since: 1.0.0
1.5.9 Fix the broken links when domain name contain CPT and home page
is set to current location.
1.6.18 Fix with WPML the location terms added twice when CPT slug is translated.
Filters
‘wpml_translate_single_string’ [Line: 1489]
Source File
geodir_listing_permalink_structure() is located in geodirectory-functions/taxonomy_functions.php [Line: 1452]
Source Code
function geodir_listing_permalink_structure($post_link, $post_obj, $leavename, $sample) { //echo $post_link."
".$sample ; global $wpdb, $wp_query, $plugin_prefix, $post, $comment_post_cache, $gd_permalink_cache; if (isset($post_obj->ID) && isset($post->ID) && $post_obj->ID == $post->ID) { if($post_obj->post_status == 'auto-draft' || $post_obj->post_status == 'draft' || $post_obj->post_status == 'pending'){return $post_link;} } elseif (isset($post_obj->post_status) && ($post_obj->post_status == 'auto-draft' || $post_obj->post_status == 'draft' || $post_obj->post_status == 'pending')) { return $post_link; } else { $orig_post = $post; $post = $post_obj; } if (in_array($post->post_type, geodir_get_posttypes())) {//print_r($post );exit; // if we dont have a GD post then try to grab it if(!isset($post->default_category)){ $gd_post = geodir_get_post_info($post->ID); if(!empty($gd_post)){ $post = $gd_post; } } $post_types = get_option('geodir_post_types'); $slug = $post_types[$post->post_type]['rewrite']['slug']; // Alter the CPT slug if WPML is set to do so if(geodir_wpml_is_post_type_translated($post->post_type)){ if ( gd_wpml_slug_translation_turned_on( $post->post_type ) && $language_code = gd_wpml_get_lang_from_url($post_link)) { $org_slug = $slug; $slug = apply_filters( 'wpml_translate_single_string', $slug, 'WordPress', 'URL slug: ' . $slug, $language_code); if(!$slug){$slug = $org_slug;} } } if (function_exists('geodir_location_geo_home_link')) { remove_filter('home_url', 'geodir_location_geo_home_link', 100000); } // Fix slug problem when slug matches part of host or base url/ Ex: url -> www.abcxyz.com & slug -> xyz. $site_url = trailingslashit(get_bloginfo('url')); if (function_exists('geodir_location_geo_home_link')) { add_filter('home_url', 'geodir_location_geo_home_link', 100000, 2); } $fix_url = strpos($post_link, $site_url) === 0 ? true : false; if ($fix_url) { $post_link = str_replace($site_url, '', $post_link); } $post_link = trailingslashit( preg_replace( "/" . preg_quote( $slug, "/" ) . "/", $slug ."/%gd_taxonomy%",$post_link, 1 ) ); if ($fix_url) { $post_link = $site_url . $post_link; } if (isset($comment_post_cache[$post->ID])) { $post = $comment_post_cache[$post->ID]; } if (isset($gd_permalink_cache[$post->ID]) && $gd_permalink_cache[$post->ID] && !$sample) { $post_id = $post->ID; if (isset($orig_post)) { $post = $orig_post; } return $gd_permalink_cache[$post_id]; } if (!isset($post->post_locations)) { $post_type = $post->post_type; $ID = $post->ID; $post2 = $wpdb->get_row( $wpdb->prepare( "SELECT * from " . $plugin_prefix . $post->post_type . "_detail WHERE post_id = %d ", array($post->ID) ) ); $post = (object)array_merge((array)$post, (array)$post2); $comment_post_cache[$post->ID] = $post; } if (false !== strpos($post_link, '%gd_taxonomy%')) { if ( apply_filters("geodir_add_location_url_to_url",get_option('geodir_add_location_url'),$post->post_type,$post)) { $location_request = ''; if (!empty($post->post_locations)) { $geodir_arr_locations = explode(',', $post->post_locations); if (count($geodir_arr_locations) == 3) { $post->city_slug = str_replace('[', '', $geodir_arr_locations[0]); $post->city_slug = str_replace(']', '', $post->city_slug); $post->region_slug = str_replace('[', '', $geodir_arr_locations[1]); $post->region_slug = str_replace(']', '', $post->region_slug); $post->country_slug = str_replace('[', '', $geodir_arr_locations[2]); $post->country_slug = str_replace(']', '', $post->country_slug); $post_location = (object)array('country_slug' => $post->country_slug, 'region_slug' => $post->region_slug, 'city_slug' => $post->city_slug ); } else $post_location = geodir_get_location(); } else { $post_location_sql = $wpdb->get_results( $wpdb->prepare( "SELECT post_locations from " . $plugin_prefix . $post->post_type . "_detail WHERE post_id = %d ", array($post->ID) ) ); if (!empty($post_location_sql) && is_array($post_location_sql) && !empty($post_location_sql[0]->post_locations)) { $geodir_arr_locations = explode(',', $post_location_sql[0]->post_locations); if (count($geodir_arr_locations) == 3) { $post->city_slug = str_replace('[', '', $geodir_arr_locations[0]); $post->city_slug = str_replace(']', '', $post->city_slug); $post->region_slug = str_replace('[', '', $geodir_arr_locations[1]); $post->region_slug = str_replace(']', '', $post->region_slug); $post->country_slug = str_replace('[', '', $geodir_arr_locations[2]); $post->country_slug = str_replace(']', '', $post->country_slug); $post_location = (object)array('country_slug' => $post->country_slug, 'region_slug' => $post->region_slug, 'city_slug' => $post->city_slug ); } } else $post_location = geodir_get_location(); } if (!empty($post_location)) { $country_slug = isset($post_location->country_slug) ? $post_location->country_slug : ''; $region_slug = isset($post_location->region_slug) ? $post_location->region_slug : ''; $city_slug = isset($post_location->city_slug) ? $post_location->city_slug : ''; $geodir_show_location_url = get_option('geodir_show_location_url'); $location_slug = array(); if ($geodir_show_location_url == 'all') { $location_slug[] = $country_slug; $location_slug[] = $region_slug; } else if ($geodir_show_location_url == 'country_city') { $location_slug[] = $country_slug; } else if ($geodir_show_location_url == 'region_city') { $location_slug[] = $region_slug; } $location_slug[] = $city_slug; $location_request .= implode('/', $location_slug) . '/'; } } if (get_option('geodir_add_categories_url')) { $term_request = ''; $taxonomies = geodir_get_taxonomies($post->post_type); $taxonomies = !empty($taxonomies) && is_array($taxonomies) ? end($taxonomies) : ''; if (!empty($post->default_category)) { $post_terms = $post->default_category; } else { $post_terms = ''; if(isset($_POST['post_default_category']) && $_POST['post_default_category']){ $post_terms = absint($_POST['post_default_category']); }elseif(isset($_POST['post_category'][$taxonomies]) && $_POST['post_category'][$taxonomies]) { $post_terms = is_array($_POST['post_category'][$taxonomies]) ? $_POST['post_category'][$taxonomies] : explode(",", trim($_POST['post_category'][$taxonomies], ",")); $post_terms = !empty($post_terms) ? absint($post_terms[0]) : 0; }elseif (isset($post->{$taxonomies})) { $post_terms = explode(",", trim($post->{$taxonomies}, ",")); $post_terms = $post_terms[0]; } if (!$post_terms) $post_terms = geodir_get_post_meta($post->ID, 'default_category', true); if (!$post_terms) { $post_terms = geodir_get_post_meta($post->ID, $taxonomies, true); if ($post_terms) { $post_terms = explode(",", trim($post_terms, ",")); $post_terms = $post_terms[0]; } } } $term = get_term_by('id', $post_terms, $taxonomies); if (!empty($term)) $term_request = $term->slug; //$term_request = $term->slug.'/'; } $request_term = ''; $listingurl_separator = ''; //$detailurl_separator = get_option('geodir_detailurl_separator'); $detailurl_separator = ''; if (isset($location_request) && $location_request != '' && isset($term_request) && $term_request != '') { $request_term = $location_request; //$listingurl_separator = get_option('geodir_listingurl_separator'); //$request_term .= $listingurl_separator.'/'.$term_request; $request_term .= $term_request; } else { if (isset($location_request) && $location_request != '') $request_term = $location_request; if (isset($term_request) && $term_request != '') $request_term .= $term_request; } $request_term = trim($request_term, '/'); // Fix with WPML the location terms added twice when CPT slug is translated. if ($sample && !empty($location_request) && geodir_is_wpml() && strpos($post_link, '%gd_taxonomy%/' . $request_term . $detailurl_separator) !== false) { $post_link = str_replace('%gd_taxonomy%/', '', $post_link); } if (!empty($request_term)) $post_link = str_replace('%gd_taxonomy%', $request_term . $detailurl_separator, $post_link); else $post_link = str_replace('/%gd_taxonomy%', $request_term . $detailurl_separator, $post_link); //echo $post_link ; } // temp cache the permalink if (!$sample && (!isset($_REQUEST['geodir_ajax']) || (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] != 'add_listing'))) { $gd_permalink_cache[$post->ID] = $post_link; } } if (isset($orig_post)) { $post = $orig_post; } return $post_link; }