WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a CPT:

function CPT_init(){
    register_post_type('custcpt', array(
        'labels'            =>  array(
            'name'          =>      __('Products'),
            'singular_name' =>      __('Product'),
            'all_items'     =>      __('View Products'),
            'add_new'       =>      __('New Product'),
            'add_new_item'  =>      __('New Product'),
            'edit_item'     =>      __('Edit Product'),
            'view_item'     =>      __('View Product'),
            'search_items'  =>      __('Search Products'),
            'no_found'      =>      __('No Products Found'),
            'not_found_in_trash' => __('No Products in Trash')
        'public'            =>  true,
        'publicly_queryable'=>  true,
        'show_ui'           =>  true, 
        'query_var'         =>  true,
        'show_in_nav_menus' =>  false,
        'capability_type'   =>  'post',
        'hierarchical'      =>  false,
        'rewrite'           =>  array('slug' => '/products/', 'with_front' => false),
        'menu_position'     =>  21,
        'supports'          =>  array('title','editor', 'thumbnail'),
        'has_archive'       =>  true
add_action('init', 'CPT_init');

And Taxonomy with my CPT:

function custcpt_category_taxonomy() {
    $labels = array(
        'name'              => __( 'Product Categories' ),
        'singular_name'     => __( 'Product Category' ),
        'search_items'      => __( 'Search Product Categories' ),
        'all_items'         => __( 'All Product Categories' ),
        'parent_item'       => __( 'Parent Product Category' ),
        'parent_item_colon' => __( 'Parent Product Category:' ),
        'edit_item'         => __( 'Edit Product Category' ), 
        'update_item'       => __( 'Update Product Category' ),
        'add_new_item'      => __( 'Add New Product Category' ),
        'new_item_name'     => __( 'New Product Category' ),
        'menu_name'         => __( 'Product Categories' ),
    $args = array(
        'labels'            => $labels,
        'public'            =>  true,
        'hierarchical'      =>  true,
        'show_in_nav_menus' =>  true,
        'has_archive'       =>  true,
        'rewrite'           =>  array('slug' => '/products/', 'with_front' => false),
    register_taxonomy( 'custtax', 'custcpt', $args );
add_action( 'init', 'custcpt_category_taxonomy');

I have a products page /products/ and a taxonomy template page: taxonomy-custtax.php, I've tried taxonomy.php but it didn't seem to matter. I've flushed my permalinks probably 15-20 times by now. It works fine with default but not with %postname%. I've added this above my taxonomy:

function custom_taxonomy_flush_rewrite() {
    global $wp_rewrite;
add_action('init', 'custom_taxonomy_flush_rewrite');

So when I go to http://www.mywebsite.com/products/term I get 404 for some reason or another. I swear taxonomy always gives me problems, every. single. time.

share|improve this question
up vote 3 down vote accepted

Remove the slashes on your rewrite slug. Should be like so:

 'rewrite'           =>  array('slug' => 'products', 'with_front' => false)

Also, you can't have the same slug for both a taxonomy and a custom post type. They need to be unique, otherwise WP won't know which one applies to which.

Additionally, if you have the slug of your custom post type as products, you cannot have a have a page with a slug of products also, otherwise that will cause conflicts.

Finally, for a custom taxonomy listing of these, you want the file to be titled taxonomy-{taxonomy_name}.php, so in your case, it should be titled taxonomy-custtax.php.

For best luck, I would suggest taking this in steps:

First, setup the custom post type. Then, if you set the slug to products (after flushing rewrite rules), visit www.mysite.com/products (again, be sure nothing else in your install has a slug of products). You should see a listing of your products (assuming you have added some product entries).

Then, add your archive-custcpt.php file to your theme, modify it in some unique way, and refresh. You should see that it is now loading your list of products within that new template.

Then, add in your custom taxonomy. If your taxonomy slug is prodcat (for products category), you should be able to visit www.mysite.com/prodcat/[term] (where [term] = a product category you have set up).

Lastly, add your taxonomy-custtax.php file, modify it in some unique way, and refresh. You should see the listing showing up in your new template file.

share|improve this answer
Ok, I've changed my CPT to have a slug of product and my taxonomy to have a slug of category - now I have an archive-product.php but it's still referring to my index.php even after flushing my peramlinks. My taxonomy still leading to 404. I have a taxonomy-category.php uploaded. – Howdy_McGee Oct 17 '13 at 20:37
@Howdy_McGee - Well, category is probably being used by WordPress for the default / built-in category taxonomy, so that's part of the issue. When you flush your rewrite rules, how are you doing it? And what url are you visiting - www.mysite.com/product ? – cale_b Oct 17 '13 at 20:39
I'm going to "Permalinks" section, saying as default, then resaving as %postname% - and when i visit my products archive I'm going to www.mysite.com/product/ – Howdy_McGee Oct 17 '13 at 20:42
That sounds like it should work. Do other permalinks work? Can you visit pages, and other posts? What happens when you click "View Product" from the dashboard, when viewing / editing a product you've added? – cale_b Oct 17 '13 at 20:45
codex.wordpress.org/… - the template would be taxonomy-{taxonomyname} instead of slug. I think ultimately my problem was my CPT having the same slug as a page. Now my taxonomy has a slug of the same page /products/ so it looks like it leads off it, then my CPT has a slug of product. The archive needs to be archive-{CPT} which in my case is archive-custcpt.php and it worked fine. Thank You – Howdy_McGee Oct 17 '13 at 20:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.