具有自定义分类法且无基名的 Wordpress 永久链接结构

问题描述

我想创建以下永久链接结构

自定义帖子类型: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');
    });

如何禁用重定向到资源?

感谢您的帮助!

解决方法

我想我找到了自己的答案。也许其他人也需要这个解决方案。

https://wordpress.stackexchange.com/questions/328279/custom-permalink-structure-custom-taxonomy-post-name-without-cpt-slug