I know this question has been asked a thousand times, but feel like I've looked at every single article on this issue, and none of them have worked for me.
All I want is for there to be a category page for my custom post type, products. So that I can type www.mysite.com/products and see all the products. Or if it's easier make it work like regular posts do www.mysite.com/category/products. Either works for me.
I have written the code in functions.php and also used plugins like CPT-onomy and CPT-UI to successfully make the custom post types and taxonomies. But this doesn't create the category page.
How is this accomplished? Please include instructions on permalinks if that is relevant to my situation too.
Here is the code I placed in functions.php. The second block that deals with taxonomies actually breaks the site. However, using the two plugins mentioned above, I've been able to successfully create taxonomies, but still can't get a category page.
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'product',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
),
'public' => true,
'has_archive' => true,
'exclude_from_search' => false,
'show_ui' => true,
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
'taxonomies' => array('category', 'post_tag')
)
);
}
function my_taxonomies_product() {
$args = array();
register_taxonomy( 'product_category', 'product' $args );
}
add_action( 'init', 'my_taxonomies_product', 0 );
updated code
function create_post_type() {
register_post_type( 'product',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
),
'public' => true,
'has_archive' => true,
'exclude_from_search' => true,
'show_ui' => true,
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
)
);
}
add_action( 'init', 'create_post_type' );
function my_taxonomies_product() {
$labels = array(
'name' => _x( 'Product Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Product Category', 'taxonomy singular name' ),
'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' ),
);
$rewrite = array(
'slug' => 'type',
'with_front' => true,
'hierarchical' => true,
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'rewrite' => $rewrite,
);
register_taxonomy( 'product_category', 'product', $args );
}
add_action( 'init', 'my_taxonomies_product', 0 );