CPT: product Taxonomy: prod_cat
Current URLs
- Child Term
domain.com/product-category/pulp/
- Hierarchical Child Term
domain.com/product-category/pulp-iqf/pulp/apple/
- Single CPT Post
domain.com/product/apple-juice-concentrate/
Desired URLs
- Child Term
domain.com/pulp/
- Hierarchical Child Term
domain.com/pulp-iqf/pulp/apple/
- Single CPT Post
domain.com/pulp-iqf/pulp/apple/apple-juice-concentrate/
I've gone through the depths of answers on WPSE and believe me I've tried various combinations but I'm unable to set it this way. The regex filled solutions around creating your own rules trips me and hence would really appreciate if someone can explain what can be done to either achieve the Desired URL structure or the way to achieve something close to the desired URLs.
//Register product post type
function products_post_type() {
$labels = array(
'name' => 'Products',
'singular_name' => 'Product',
'menu_name' => 'Products',
'name_admin_bar' => 'Post Type',
'parent_item_colon' => 'Parent Product:',
'all_items' => 'All Products',
'add_new_item' => 'Add New Product',
'add_new' => 'New Product',
'new_item' => 'New Item',
'edit_item' => 'Edit Product',
'update_item' => 'Update Product',
'view_item' => 'View Product',
'search_items' => 'Search products',
'not_found' => 'No products found',
'not_found_in_trash' => 'No products found in Trash',
'items_list' => 'Items list',
'items_list_navigation' => 'Items list navigation',
'filter_items_list' => 'Filter items list',
);
$args = array(
'label' => 'Product',
'description' => 'Products Post Type',
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'rewrite' => array(
'slug' => 'product',
'hierarchical' => true,
'with_front' => false,
)
);
register_post_type( 'product', $args );
}
add_action( 'init', 'products_post_type', 0 );
// Register Product Category
function prod_cat() {
$labels = array(
'name' => 'Product Categories',
'singular_name' => 'Product Category',
'menu_name' => 'Product Category',
'all_items' => 'All Items',
'parent_item' => 'Parent Item',
'parent_item_colon' => 'Parent Item:',
'new_item_name' => 'New Item Name',
'add_new_item' => 'Add New Item',
'edit_item' => 'Edit Item',
'update_item' => 'Update Item',
'view_item' => 'View Item',
'separate_items_with_commas' => 'Separate items with commas',
'add_or_remove_items' => 'Add or remove items',
'choose_from_most_used' => 'Choose from the most used',
'popular_items' => 'Popular Items',
'search_items' => 'Search Items',
'not_found' => 'Not Found',
'items_list' => 'Items list',
'items_list_navigation' => 'Items list navigation',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => array( 'slug' => 'product-category',
'hierarchical' => true,
'with_front' => false,
)
);
register_taxonomy( 'prod_cat', array( 'product' ), $args );
}
add_action( 'init', 'prod_cat', 0 );
register_post_type
orregister_taxonomy
, it will require a custom rewrite rule, which means regular expressions are unavoidable