Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bis_duplicated_uri($element_id, $uri_parts, $request_url) {
- global $permalink_manager_uris, $wpdb;
- if(isset($_GET['test']) && !empty($uri_parts['uri'])) {
- // Get detected URI
- $uri = $uri_parts['uri'];
- // Check if URI is used more than once
- $duplicates = array_keys($permalink_manager_uris, $uri);
- if(!empty($duplicates) && count($duplicates) > 1) {
- $duplicates = array_map(function($value) { return str_replace('tax-', '', $value); }, $duplicates);
- $term_ids = implode(", ", $duplicates);
- // Exclude the post categories
- $new_term_id = $wpdb->get_var("SELECT term_id FROM {$wpdb->term_taxonomy} AS tt WHERE tt.taxonomy != 'category' AND term_ID IN ({$term_ids}) ORDER BY term_id DESC LIMIT 1");
- }
- }
- return (!empty($new_term_id))? "tax-{$new_term_id}" : $element_id;
- }
- add_filter('permalink_manager_detected_element_id', 'bis_duplicated_uri', 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement