The page not found error doesn’t mean that the template file is not found/used. Note that a URL returns a 404 status header (not found), then 404.php is used (or index.php if 404.php doesn’t exist).
I think your real problem is that you have not flushed the rewrite rules after the taxonomy has been registered. To do it, follow these steps:
Manually: go to settings->permalinks and click the save button (you don’t need to change anything, just click the save button).
Auto: in your plugin, use flush_rewrite_rules()
during plugin activation hook (never use flush_rewrite_rules()
on every page load). For example:
register_activation_hook( __FILE__, 'cyb_plugin_activation' );
function cyb_plugin_activation() {
cyb_register_taxonomy();
flush_rewrite_rules();
}
add_action( 'init', 'cyb_register_taxonomy' );
function cyb_register_taxonomy() {
$specialty_args = array(
'hierarchical' => false,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => 'Specialty',
'singular_name' => 'Specialty',
'search_items' => 'Search specialties',
'all_items' => 'All specialties',
'edit_item' => 'Edit specialty',
'update_item' => 'Update specialty',
'add_new_item' => 'Add new specialty',
'new_item_name' => 'New specialty name',
'menu_name' => 'Specialties',
),
'show_ui' => true,
'show_admin_column' => true,
'query_var' => 'specialty',
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'events/specialty', // This controls the base slug that will display before each term (renamed to specialty from specialties)
'with_front' => false, // Don't display the category base before "/specialties/"
'hierarchical' => false
),
);
register_taxonomy('specialty', 'event', $specialty_args);
register_taxonomy_for_object_type('specialty', 'event');
}
register_deactivation_hook( __FILE__, 'cyb_plugin_deactivation' );
function cyb_plugin_deactivation() {
// Flush the rewrite rules also on deactivation
flush_rewrite_rules();
}