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 domain.com/media-center/articles - 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' ),
));
}
template_include
filters and rewrite rules are both plausible culprits for this behavior. The former can change which template file is loaded for a query and the latter can change a query which is produced for a URL - so either might result in a different template being loaded at the same URL. A new taxonomy registration is unlikely to be the source. You mightvar_dump()
the$wp_query
global at the top of the erroneous template in order to examine the query (or use something like Query Monitor) and ensure it is as you would expect for that URLpost_type=offices
but a page displaying incorrectly shows the query:year=about-us
. This appears to be affected by my latest taxonomy (in original question) in some way - but I'm not sure why this is happening or how to resolve. I tried removing the taxonomy from functions (and nuking all functions content as a test) but the issue remained. Any ideas for next steps?