CPT:产品分类法:prod\\U cat
当前URL
子术语domain.com/product-category/pulp/
分层子项domain.com/product-category/pulp-iqf/pulp/apple/
单个CPT岗位domain.com/product/apple-juice-concentrate/
所需URL
子术语domain.com/pulp/
分层子项domain.com/pulp-iqf/pulp/apple/
单个CPT岗位domain.com/pulp-iqf/pulp/apple/apple-juice-concentrate/
我已经深入了解了WPSE的答案,相信我,我尝试了各种组合,但我无法这样设置。关于创建您自己的规则的充满regex的解决方案让我感到困惑,因此如果有人能够解释如何实现所需的URL结构或如何实现接近所需URL的内容,我将不胜感激。
//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 );