我一直在遵循answer here 它创造了奇迹。
但我的问题是在这方面,
在原件上:
add_filter(\'rewrite_rules_array\', \'mmp_rewrite_rules\');
function mmp_rewrite_rules($rules) {
$newRules = array();
$newRules[\'custom-post-type-base/(.+)/(.+)/(.+)/(.+)/?$\'] = \'index.php?custom_post_type_name=$matches[4]\'; // my custom structure will always have the post name as the 5th uri segment
$newRules[\'custom-post-type-base/(.+)/?$\'] = \'index.php?taxonomy_name=$matches[1]\';
return array_merge($newRules, $rules);
}
我的版本:add_filter(\'rewrite_rules_array\', \'mmp_rewrite_rules\');
function mmp_rewrite_rules($rules) {
$newRules = array();
$newRules[\'custom-post-type-base/(.+)/(.+)/(.+)/?$\'] = \'index.php?custom_post_type=$matches[3]\';
$newRules[\'custom-post-type-base/(.+)/?$\'] = \'index.php?custom_taxonomy=$matches[1]\';
return array_merge($newRules, $rules);
}
由于我的分类法有两个级别,它无法识别第二个参数(custom-post-type-base/(.+)/[here]/
) 是自定义帖子或自定义分类法。。它在自定义分类法上正确返回,但在自定义帖子类型上返回404,帖子类型在父分类法上分类。请参见示例URL:
"/custom-post-type-base/taxonomy-parent/taxonomy-child/single-custom-post-type/"
/*works as single custom post*/
"/custom-post-type-base/taxonomy-parent/taxonomy-child/"
/*works as custom taxonomy page*/
"/custom-post-type-base/taxonomy-parent/"
/*works as custom taxonomy page too*/
"/custom-post-type-base/taxonomy-parent/single-custom-post-type/"
/*returns a 404*/