WordPress Custom Taxonomy – Volume / Issue – Unique Slug Issue

There are a lot of ways you can solve this issue. What I’d do if it were me is to make “issue” its own taxonomy.

If issue is its own taxonomy, then the terms can be unique (and things are much less cluttered). An article will then belong to a volume, and also an issue. The trick is to create a hierarchy in the rewrite rules to make issues a part of volumes, and articles a part of both.

Here, I’m going to make your URLS look like this:

  • /volume/1/
  • /volume/1/issue/2/
  • /volume/1/issue/2/article-title/

In your article post type declaration, you’ll want to set:

'rewrite' => array( 'slug' => 'volume/%volume%/issue/%issue%' )

In your issue taxonomy declaration, you’ll want to set:

'rewrite' => array( 'slug' => 'volume/%volume%/issue' )

Lastly, you’ll want to add filters to post_type_link and term_link so the auto-generate links don’t contain %volume% and %issue%. Rather than reinvent the wheel, see “How do I append multiple taxonomies to the URL?” (amongst many, many others) on how to do that.

As always when making rewrite changes, be sure to flush your rewrite rules. You can do so by going to Settings->Permalinks and clicking “Save Changes”.