Created
April 20, 2017 15:43
-
-
Save fridaynext/a00495da056fee8ad6c81271e13b8840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// custom post type permalinks | |
add_filter('post_type_link', 'deb_permalink', 10, 4); | |
function deb_permalink($permalink, $post_id, $leavename) { | |
if (strpos($permalink, '%taxonomy_name%') === FALSE) return $permalink; | |
// Get post | |
$post = get_post($post_id); | |
if (!$post) return $permalink; | |
// Get taxonomy terms | |
$terms = wp_get_object_terms($post->ID, 'product_types'); | |
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) { | |
$taxonomy_slug = ''; | |
if ( $terms[0]->parent ) { | |
$taxonomy_slug .= $terms[1]->slug; | |
$taxonomy_slug .= '/'; | |
} | |
$taxonomy_slug .= $terms[0]->slug; | |
} else | |
$taxonomy_slug = 'other'; | |
return str_replace('%taxonomy_name%', $taxonomy_slug, $permalink); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment