WordPress add_rewrite_rule不返回$matches[]数组项

我正在尝试匹配以下网址:

planets/animals-and-more/animal/human

至:
index.php?pagename=animal& animal-name=human

其中” 动物” 页面具有自定义的page-animal.php模板, 该模板可提取” 动物名称” 查询变量并将其吐入。
我已经设置了重写标签:
function animal_custom_rewrite_tag() { add_rewrite_tag('%animal-name%', '([^& ]+)'); } add_action('init', 'animal_custom_rewrite_tag', 10, 0);

以及重写规则:
function add_some_rewrite_rules() { global $wp_rewrite; add_rewrite_rule('^planets/animals-and-more/animal/[a-zA-Z0-9]*$', 'index.php?pagename=animal& animal-name=$matches[4]', 'top'); $wp_rewrite-> flush_rules(); } add_action( 'init' , 'add_custom_ncta_rewrite_rules' );

如果我将字符串硬编码为” animal-name = monkey” , 则重写规则有效, 但似乎matchs [n]数组根本不起作用。
我知道通过修改htaccess都可以实现, 但是我需要Wordpress的解决方案。
知道为什么$ matches []根本不起作用吗?
#1找到了!
来自theme.fm的本文提到, matchs [n]数组仅适用于用括号括起来的正则表达式中的组。例如:
要使$ matches1进入” 行星/更多动物/动物/人类” 时返回” 人类” , 重写规则应如下所示:
add_rewrite_rule('^planets/animals-and-more/animal/([a-zA-Z0-9-_]+)$', 'index.php?pagename=sponsorship& sponsorship_item=$matches[1]', 'top');

【WordPress add_rewrite_rule不返回$matches[]数组项】在你要” 匹配” 的组中使用()。

    推荐阅读