My custom taxonomy is linking to yearly archive instead of the post linked to it.
I have created a custom taxonomy named “year” containing int (i.e 2008,2009,2010 etc). Have registered the custom taxonomy using the following code.
// Add new "Years" taxonomy to Posts
register_taxonomy('year', 'post', array(
// Hierarchical taxonomy (like categories)
'hierarchical' => true,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => _x( 'Year', 'taxonomy general name' ),
'singular_name' => _x( 'Year', 'taxonomy singular name' ),
'search_items' => __( 'Search Years' ),
'all_items' => __( 'All Years' ),
'parent_item' => __( 'Parent Year' ),
'parent_item_colon' => __( 'Parent Year:' ),
'edit_item' => __( 'Edit Year' ),
'update_item' => __( 'Update Year' ),
'add_new_item' => __( 'Add New Year' ),
'new_item_name' => __( 'New Year Name' ),
'menu_name' => __( 'Years' ),
),
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'Years', // This controls the base slug that will display before each term
'with_front' => false, // Don't display the category base before "/Years/"
'hierarchical' => true // This will allow URL's like "/Years/boston/cambridge/"
),
));
and echoed the year taxonomy under post using the following line.
<?php echo get_the_term_list( $post->ID, 'year', '<li>', '</li><li>', '</li>' ); ?>
I have registered two other taxonomies “player” and “team” in the same manner which are working perfectly.
Any help in this regard will be appreciated.
I would advise against the use of
year
as a post type or taxonomy name as its a reserved term and your rewrite rule may clashFor a list of reserved terms see here
Steps to take:
year
to something unique that isn’t reserved