I want to create canonical permalinks for products and product types. I have the custom post types and custom taxonomy figured out, but I don't know if its possible to define permalinks with taxonomies. So my workflow, for example, would be this...
- I create a custom post type called products.
- Then I create a custom taxonomy for product types.
- Then I add a product type called 'Chairs' and add a product called 'Red Chair' to this category.
Once I create this product, the desired permalink structure to view this product would be formatted like so ->
http://shop.com/products/chairs/red-chair
Is this possible in wordpress 3.4? The meta boxes in my custom post type allow for selecting of the product types defined for my custom taxonomy, and there will only ever be one type per product.
If possible, I would also like to include any parents of the selected product category if possible (For example, if the 'chairs' category was a child of the 'lounge' category, the permalink structure would be as follows ->
http://shop.com/products/lounge/chairs/red-chair
Here is how I create the custom post type and the custom taxonomy, I just need help defining rewrite / slug rules to include product type in the permalink.
/* Custom Post Type - Products ------- */
function products_init() {
$args = array(
'public' => true,
'label' => 'Products'
);
register_post_type( 'products', $args );
}
add_action( 'init', 'products_init' );
/* Custom Taxonomy - Product Type ------- */
add_action( 'init', 'create_prodtype' );
function create_prodtype() {
$labels = array(
'name' => _x( 'Product Type', 'products' ),
'singular_name' => _x( 'Product Category', 'product' ),
'search_items' => __( 'Search Product Types' ),
'all_items' => __( 'All Product Types' ),
'parent_item' => __( 'Products' ),
'parent_item_colon' => __( 'Products:' ),
'edit_item' => __( 'Edit Product Type' ),
'update_item' => __( 'Update Product Type' ),
'add_new_item' => __( 'Add New Product Type' ),
'new_item_name' => __( 'New Product Type' ),
);
register_taxonomy(
'products',
array('products'),
array(
'rewrite' => array(
'slug' => 'products',
'hierarchical' => true
),
'with_front' => false,
'labels' => $labels
));
}
http://shop.com/products/lounge/chairs/red/fancy-chair
will most-likely not work. – Nikola Ivanov Nikolov