0

I have a custom taxonomy (editions) and would like to have a year / month hierarchy in the taxonomy reflected in the URL structure.

/editions/2016/december
/editions/2017/december
/editions/2018/december

WordPress doesn't seem to allow me to create this on the admin side. Is this possible?

For reference, here is my custom taxonomy setup inside of my functions.php:

/* Editions Function */
function aa_editions_tax() {
  register_taxonomy( 'editions', 'page', array(
    'labels' => array(
      'add_new_item' => 'Add New Edition',
      'all_items' => 'All Editions',
      'edit_item' => 'Edit Edition',
      'menu_name' => 'Editions',
      'name' => 'Editions',
      'new_item' => 'New Edition',
      'not_found' => 'No Editions Found',
      'not_found_in_trash' => 'No Editions Found in Trash',
      'parent' => 'Parent of Edition',
      'search_items' => 'Search Editions',
      'singular_name' => 'Edition',
      'view_item' => 'View Edition'
    ),
    'hierarchical' => true,
    'public' => true,
        'rewrite' => array(
            'hierarchical' => true
        ),
    'query_var' => true,
    'show_ui' => true
  ));
}
add_action( 'init', 'aa_editions_tax' );
1

EDIT

Since you can only have unique term slugs in a taxonomy, you should go for a "mixed taxonomy term" url setup.

You can check this, or this solution that involve creating your own add_rewrite_rules.

| improve this answer | |
  • Thanks J. This is exactly what I did but when you create the identical children, December for example, WordPress will not give those children the same slug. They get slugs like december-2017 and december-2018, etc. Any idea how to get that to happen? – serraosays Aug 31 '16 at 11:54
  • Another method is to just do a combination of month and year into the same top-level category 2016-January - it wouldn't be the end of the world. – serraosays Aug 31 '16 at 11:55
  • true @staypuftman. in the same taxonomy you can only have unique slugs. you'll have to go for a mixed taxonomy-term, solution. – The J Aug 31 '16 at 12:03
  • Thanks for the info - seems crazy you can't do this. Are we missing something in the codex? – serraosays Aug 31 '16 at 13:36
  • @staypuftman well it makes sense that an url is univocal and unambiguous. however I think that a better term relationship, db-wise, would help. – The J Aug 31 '16 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.