好吧,我已经阅读了这个问题的几乎所有答案,但我的情况一定是独一无二的。
我试图做的理论上很简单。
注册CPT时,我设置了以下内容:
\'rewrite\' => array(
\'slug\' => \'resources/%resource_type%\',
\'with_front\' => false
),
\'with_front\' => false
因为标准立柱使用底座。我还有一页example.com/resources
模板为page-resources.php
.
当我注册Tax1时,我设置了以下内容:
\'rewrite\' => array(
\'slug\' => \'resources\',
\'with_front\' => false
)
我有一个resource_type
名称为的术语white-papers
.这产生了我第一个想要的permalink结果example.com/resources/white-papers/
对于分类法存档页,请使用taxonomy-resource_type.php
.
这就是事情变得棘手的地方。我试图做的是添加第二个分类法(Tax2),并创建另一个永久链接为:
example.com/resources/white-papers/enterprise
resource_type = white-papers
和industry = enterprise
.相反,我得到404
.
但如果我尝试使用查询example.com/index.php?post_type=resource&resource_type=white-papers&industry=enterprise
我获得了所需的筛选存档页面。
此外,我不确定它是否与问题相关,但我运行了此函数:
function resources_cpt_generating_rule($wp_rewrite) {
$rules = array();
$terms = get_terms( array(
\'taxonomy\' => \'resource_type\',
\'hide_empty\' => false,
) );
$post_type = \'resource\';
foreach ($terms as $term) {
$rules[\'resources/\' . $term->slug . \'/([^/]*)$\'] = \'index.php?post_type=\' . $post_type. \'&resource_type=$matches[1]&name=$matches[1]\';
}
// merge with global rules
$wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_filter(\'generate_rewrite_rules\', \'resources_cpt_generating_rule\');
我需要帮助的是实现这一点的重写规则。任何帮助都将提前感谢!