问题描述
我想创建以下永久链接结构
自定义帖子类型:resources
自定义分类:resources-category
(例如销售、业务、...)
我怎样才能得到这个结构:url.com/%resources-category%/detail-slug
例如url.com/sales/how-to-sale
url.com/business/how-to-something
到目前为止我得到的是,我可以打开这个网址,但它们会自动重定向到我的自定义帖子类型 resources
slug
例如
url.com/sales/how-to-sale
重定向到 url.com/resources/how-to-sale
我注册了帖子类型:
function registerTypeResources () {
register_post_type('resources',array(
'labels' => array(
'name' => __('Resources'),'singular_name' => __('Resources')
),'public' => true,'has_archive' => false,'supports' => array('title','thumbnail','editor'),'show_in_rest' => true,)
);
}
add_action('init','registerTypeResources');
add_action('init','registerRessourcesTaxonomy',0);
function registerRessourcesTaxonomy () {
register_taxonomy(
'resources-category','resources',array(
'labels' => array(
'name' => __('Categories'),'add_new_item' => __('Add new category'),'new_item_name' => __('New category ')
),'show_ui' => true,'show_tagcloud' => false,'hierarchical' => true
)
);
}
我添加了重写:
add_action('init',function () {
add_rewrite_rule('sales/(.+)/?$','index.PHP?resources=$matches[1]','bottom');
add_rewrite_rule('business/(.+)/?$','bottom');
});
如何禁用重定向到资源?
感谢您的帮助!