0

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
4
  • You're going to need to make it hierarchical. Have you considered instead just having /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, 2020 at 19:21
  • @TomJNowell Hierarchical doesn't work for my use. I'm probably going to just put it in the slug.
    – jxxe
    Oct 10, 2020 at 19:32
  • Hierarchical just changes the user interface in WP Admin, they're both stored and work the same
    – Tom J Nowell
    Oct 10, 2020 at 20:18
  • @TomJNowell I had no idea about that. I'll experiment a bit, thanks!
    – jxxe
    Oct 10, 2020 at 20:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.