Custom Taxonomy leads to 404 page

Followings are the codes I added in my theme function.php file

// Taxonomy Resource
$labels = array(
    'name'              => 'Resources',
    'singular_name'     => 'Resource',
    'search_items'      => 'Search Resource',
    'all_items'         => 'All Resource',
    'parent_item'       => 'Parent Resource',
    'parent_item_colon' => 'Parent Resource:',
    'edit_item'         => 'Edit Resource',
    'update_item'       => 'Update Resource',
    'add_new_item'      => 'Add New Resource',
    'new_item_name'     => 'New Resource Name',
    'menu_name'         => 'Resource',
);

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'resource', 'with_front' => false ),
);

register_taxonomy( 'resource', array( 'post' ), $args );

and I used the following line of code to display it in front-end

<?php echo get_the_term_list( $post->ID, 'resource', 'Resource: ', ', ' ); ?>

When I click the resource items in front end, it leads to a url like this:
http://site-name/resource/test/

But instead of showing the default archive template, it shows a 404 page.
After that I created taxonomy-resource.php file and copied the codes from archrive.php

And the result is same, it gives a 404 page.

1 Answer
1

You can add flush_rewrite_rules() after registering your custom taxonomy.

NOTE:
Flush rules only on activation or deactivation, or when you know that
the rewrite rules need to be changed. Don’t do it on any hook that
will triggered on a routine basis. More detail information in the
comments on WP Engineer’s post: Custom Post Type and Permalink

OR

You can go to Settings → Permalinks → Save Permalinks, that should flush the rewrite rules manually.

Leave a Comment