I have a custom taxonomy (I’ll call ‘issues’ in this example) registered as such:
register_taxonomy('issues',array('post', 'pieces'), array(
...
'rewrite' => array( 'slug' => 'issues', 'with_front' => true, ),
...
));
This works how I like and sends the archive page for each term to www.example.com/issues/january/
. Next I want posts within this taxonomy term to show up as www.example.com/issues/january/post-name/
However, I’ve tried many different forms of rewrites and filters and have so far only managed to get the permalinks to be www.example.com/january/post-name
but I would prefer to keep the taxonomy base name (/issues/
) in the URL as it is for the taxonomy archives. I have gone into Settings>Permalinks and added %issues%
to the Custom Structure (and I also make sure to flush permalinks every single time I make a change). Below is the filter rule I have currently:
add_filter('post_link', 'issues_post_permalink', 10, 3);
function issues_post_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%issues%') === FALSE) return $permalink;
$post = get_post($post_id);
if (!$post) return $permalink;
$terms = wp_get_object_terms($post->ID, 'issues');
$term_slug = $terms[0]->slug;
return str_replace('%issues%', $taxonomy_slug, $permalink);
}
If I try adding issues/%issues%
to the Custom Structure that also does not work, though I am not sure why. I think I am missing some sort of rewrite rule, but I’ve tried to adapt a few from other threads and they don’t seem to work. Most of the other ‘guides’ and threads involve a custom post type and I ‘d prefer to not have to add one of those if possible.