具有CPT和自定义分类的层级URL 时间:2015-05-27 作者:Nathan Hornby 我很难弄清这一点,我所要做的就是为自定义分类法创建一个完美的逻辑URL结构。我有一个CPT:\'knowledgebase\'我有一个用于此CPT的自定义分类法:\'knowledgebase_topics\'我想要一个这样的url:domain.tld/knowledgebase/%knowledgebase_topic%我得到的最接近的结果是:domain.tld/topics/%knowledgebase_topic%离得很近,但没有雪茄。当前分类法和CPT代码:register_post_type( \'knowledgebase\', array( \'labels\' => array( \'name\' => __( \'Knowledgebase\' ), \'singular_name\' => __( \'Article\' ) ), \'public\' => true, \'has_archive\' => true, \'rewrite\' => array( \'slug\' => \'knowledgebase\' ), \'taxonomies\' => array(\'knowledgebase_topics\'), \'menu_position\' => 20, \'menu_icon\' => \'dashicons-sos\', \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'thumbnail\' ) ) ); register_taxonomy( \'knowledgebase_topics\', \'knowledgebase\', array( \'labels\' => array(\'name\' => \'Topics\' , \'singular_name\' => \'Topic\', \'add_new_item\' => \'Add new topic\', \'not_found\' => \'No topics found\' ), \'hierarchical\' => true, \'rewrite\' => array( \'hierarchical\' => true, \'slug\' => \'topics\' ), \'capabilities\' => array( \'edit_terms\' => \'manage_categories\' ) ) ); 那么我错过了什么把戏呢? 1 个回复 最合适的回答,由SO网友:TheDeadMedic 整理而成 在您的rewrite 参数,添加\'with_front\' => false, 然后对分类法进行更改\'slug\' => \'topics\' 到\'slug\' => \'knowledgebase\'.最后,切换注册顺序-以便register_taxonomy 首先调用。这将把分类法重写规则置于post类型规则之上(否则后者将捕获前者,因为您有匹配的slug)。刷新永久链接(只需在管理中重新保存它们),就可以了。 结束 文章导航