I've created a custom taxonomy that allows my school's newspaper to organize stories into special issues. However, some of the special issues we publish are the same every year. For example, our Black History Month special issue is published every February. Because the issues have the same name, they will have the same slug, and it will look like this:
What I have now:
https://example.com/special/black-history-month
https://example.com/special/black-history-month-1
https://example.com/special/black-history-month-2
I would like to rewrite the URL to include the year that the taxonomy was created. It seems like the date isn't stored by WordPress, so I was going to include it in an ACF custom field (I'm using the year elsewhere):
What I want:
https://example.com/special/2018/black-history-month
https://example.com/special/2019/black-history-month
https://example.com/special/2020/black-history-month
This looks a lot like how hierarchical taxonomy URLs look, however the special-issue
taxonomy is not:
register_taxonomy('special-issue', ['post'], [
'labels' => [
'name' => 'Special Issues',
'singular_name' => 'Special Issue',
'add_new_item' => 'Add New Issue',
'not_found' => 'No special issues found.',
'search_items' => 'Search',
'view_item' => 'View Special Issue'
],
'hierarchical' => false,
'show_ui' => true,
'show_admin_column' => false,
'query_var' => true,
'rewrite' => ['slug' => 'special'],
]);
Is this feasible, or should I just put the year in the slug?
What I might have to settle for:
https://example.com/special/black-history-month-2018
https://example.com/special/black-history-month-2019
https://example.com/special/black-history-month-2020
/special/block-history-month/2020
? Making it work otherwise will mean you'll need rewrite rules which will require writing regular expressions, as well as a tonne of filters as post URLs and archives won't just magically switch to the new URLs on their own. You'd also need custom code to assemble the URLs on the frontend as there won't be a function that would return these new URLs with the year in. Just setting hierarchical to true will be 10000x easier and faster – Tom J Nowell♦ Oct 10 '20 at 19:21