I have a custom post type 'profile'. Each profile can be one and only one of either student, staff or alumni, which is set through the 'profile_types' custom taxonomy. This gives me permalinks of:
www.mysite.com/profile/arthur-mcmillan.
What I want is:
www.mysite.com/student/arthur-mcmillan
I have actually got it to work using the following technique, but it breaks all my other pages and posts, returning a page not found.
In register profile custom post type:
'rewrite' => array('slug' => '%profile_types%', 'with_front' => false)
And I'm filtering it with this function:
function filter_post_type_link($link, $post)
{
if ($post->post_type != 'profile'){
return $link;
}
if ($cats = get_the_terms($post->ID, 'profile_types')){
$link = str_replace('%profile_types%', array_pop($cats)->slug, $link);
}
return $link;
}
add_filter('post_type_link', 'filter_post_type_link', 10, 2);
So that works, but breaks other ordinary pages and posts. Does anyone know a way to fix the posts and pages, or of a better way of changing the permalink?
Thanks