Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pm_wildcard_permalinks($element_id, $uri_parts) {
- global $permalink_manager_uris;
- if(empty($element_id) && !empty($uri_parts['uri']) && strpos($uri_parts['uri'], 'product/') !== false) {
- $product_slug = basename($uri_parts['uri']);
- $regex = sprintf("product\/(.*)\/%s$", preg_quote($product_slug, '/'));
- $matches = preg_grep("/{$regex}/i", $permalink_manager_uris);
- if(!empty($matches)) {
- $matches = array_flip($matches);
- $new_element_id = reset($matches);
- }
- }
- return (!empty($new_element_id)) ? $new_element_id : $element_id;
- }
- add_action('permalink_manager_detected_element_id', 'pm_wildcard_permalinks', 9999, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement