Crazy Horse
asked on
Custom post type url path not showing taxonomy
I have a custom taxonomy which has about 3 levels, parent, child, grandchild which is visible in the URL when you drill down eg:
And then after grandchild you get to the actual post type. But, I was hoping the url would be:
example.com/products/my-pr oduct
So, I am losing that whole taxonomy path.
example.com/my-cagegory/parent/child/grandchild/
And then after grandchild you get to the actual post type. But, I was hoping the url would be:
example.com/my-cagegory/parent/child/grandchild/my-product
But instead it is:example.com/products/my-pr
So, I am losing that whole taxonomy path.
function my_post_types() {
register_post_type('product', array(
'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
'rewrite' => array('slug' => 'products'),
'has_archive' => true,
'public' => true,
'labels' => array(
'name' => 'Products',
'add_new_item' => 'Add New Product',
'edit_item' => 'Edit Product',
'all_items' => 'All Products',
),
'menu_icon' => 'dashicons-cart'
));
}
add_action('init', 'my_post_types');
function my_product_taxonomy() {
$labels = array(
'name' => _x( 'Product Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Product Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
'menu_name' => __( 'Product Categories' ),
);
register_taxonomy('productCategory',array('product'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'hierarchical' => true, 'slug' => 'product-category' ),
));
}
add_action('init', 'my_product_taxonomy', 0);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A quick comment - Rewrite rules at the web server level are a possible option at least. That could involve editing the .htaccess file for the site.
ASKER
https://en-gb.wordpress.org/plugins/custom-post-type-permalinks/https://en-gb.wordpress.or
But the issue I have is that the path up until the product changes once you hit the actual product-single.php
So, up until that point it is:
Open in new window
Then it changes to:
Open in new window
So, it changes 'my-category' to 'product'. Not sure if that is because of the way I have set up my custom post type/taxonomy or what do you think there?