对于第一个首选项,您需要过滤其他重写规则,如下所示;
function __extra_country_rewrite_rules( $rules )
{
global $wp_rewrite;
if ( !isset( $wp_rewrite ) )
$wp_rewrite = new WP_Rewrite;
$m1 = $wp_rewrite->preg_index(1); // preg match backreferences
$m2 = $wp_rewrite->preg_index(2);
$m3 = $wp_rewrite->preg_index(3);
$rules[\'country/([^/]+)/([^/]+)s/feed/(feed|rdf|rss|rss2|atom)/?$\'] = "index.php?country=$m1&post_type=$m2&feed=$m3";
$rules[\'country/([^/]+)/([^/]+)s/(feed|rdf|rss|rss2|atom)/?$\'] = "index.php?country=$m1&post_type=$m2&feed=$m3";
$rules[\'country/([^/]+)/([^/]+)s/page/?([0-9]{1,})/?$\'] = "index.php?country=$m1&post_type=$m2&paged=$m3";
$rules[\'country/([^/]+)/([^/]+)s/?$\'] = "index.php?country=$m1&post_type=$m2";
return $rules;
}
add_filter( \'country_rewrite_rules\', \'__extra_country_rewrite_rules\' );
第二个不太动态,因为您需要在重写中硬编码帖子类型(URL中没有初始的“标识符”,不像前者中的“国家”)。
function __extra_country_rewrite_rules( $rules )
{
global $wp_rewrite;
if ( !isset( $wp_rewrite ) )
$wp_rewrite = new WP_Rewrite;
$m1 = $wp_rewrite->preg_index(1); // preg match backreferences
$m2 = $wp_rewrite->preg_index(2);
$m3 = $wp_rewrite->preg_index(3);
$rules["(event|contact)s/country/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$"] = "index.php?post_type=$m1&country=$m2&feed=$m3";
$rules["(event|contact)s/country/([^/]+)/(feed|rdf|rss|rss2|atom)/?$"] = "index.php?post_type=$m1&country=$m2&feed=$m3";
$rules["(event|contact)s/country/([^/]+)/page/?([0-9]{1,})/?$"] = "index.php?post_type=$m1&country=$m2&paged=$m3";
$rules["(event|contact)s/country/([^/]+)/?$"] = "index.php?post_type=$m1&country=$m2";
return $rules;
}
add_filter( \'rewrite_rules_array\', \'__extra_country_rewrite_rules\' );
您需要刷新永久链接以使更改生效(添加代码后只需访问永久链接设置页面)。
如果您发现问题仍然无法正常运行,请使用用于注册帖子类型的代码更新您的问题;自定义分类法。