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;
$wp_rewrite->flush_rules();
}
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.