functions – Custom Post Types using wrong template (index) instead of archive-{type}.php – previously worked as expected


I have several custom post types on a site where top-level nav items use archive-{post-type}.php templates of the post types. These have recently had a template problem and they now use the index.php template, instead of their archive template. This is possibly after I added a custom taxonomy to the end of functions.php (below), but only because this is the most recent significant change to functions. They still use the correct archive templates on our production site, but not on the development site, where changes have been made.

I’ve tried removing the taxonomy action, no change.

I’ve tried saving permalinks in admin settings, no change.

Also maybe relevant: this also only affects top-level templates – there are several custom post types with rewrites to eg – and the articles for these work as expected.

I’ve not faced this issue before and haven’t yet found any solutions that resolve it. Is there anything that I can check that might be causing it – or a way to get to the bottom of the issue?

The recently added taxonomy:

add_action( 'init', 'create_year_taxonomy' );
function create_year_taxonomy() {
  // translations for GUI
  $labels = array(
    'name' => _x( 'Edition Year', 'taxonomy general name' ),
    'singular_name' => _x( 'Year', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Years' ),
    'all_items' => __( 'All Years' ),
    'parent_item' => __( 'Parent Year' ),
    'edit_item' => __( 'Edit Year' ), 
    'update_item' => __( 'Update Year' ),
    'add_new_item' => __( 'Add New Year' ),
    'new_item_name' => __( 'New Year' ),
    'menu_name' => __( 'Years' ),
  // register the taxonomy
  register_taxonomy('year',array('the_street_view'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_in_rest' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'year' ),

Mike 2 weeks 2022-09-13T12:43:42-05:00 0 Answers 0 views 0

Leave an answer