Let me rephrase:
My CPT is DR12. Any post in that CPT is rendered as “~/dr12/{post-title}”.
My Custom Taxonomy is “spectro”. How do I get it so any post assigned to that CTC get spectro added to the URL so it reads: “~/dr12/spectro/{post-title}”
N.B.: I only want this to occur when I specifically assign posts to that taxonomy. Otherwise I don’t want any additional slug to appear (i.e. keep it at “~/dr12/{post-title}”).
Hi,
I’ve already answered you via email, but I’ll post it here also for other people who might have the same problem.
Basically that’s not possible by default with WordPress. You might have a look at this forum post: http://wordpress.org/support/topic/insert-category-of-taxonomy-between-custom-post-type-and-post
We do have support for the Rewrite Slug in WCK (in the Advanced Options when you create a CPT), but it’s not dynamic (unless you custom code it).
In the post above you’ll see code like:
/*Filtro per modificare il permalink*/
add_filter('post_link', 'brand_permalink', 1, 3);
add_filter('post_type_link', 'brand_permalink', 1, 3);
function brand_permalink($permalink, $post_id, $leavename) {
//con %brand% catturo il rewrite del Custom Post Type
if (strpos($permalink, '%brand%') === FALSE) return $permalink;
// Get post
$post = get_post($post_id);
if (!$post) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'brand');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
$taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = 'no-brand';
return str_replace('%brand%', $taxonomy_slug, $permalink);
}
Basically he’s replacing the %brand% with the actual term slug.