两点:
你的规则不是特别具体。对于数字匹配,您应该具体说明,并指定a)位数和b)位数。年份将是([0-9]{4})
, 月/日为([0-9]{1,2})
.
只有一条规则是做不到的。改为添加三条单独的规则。
add_rewrite_rule( \'whats-on/([0-9]{4})/?$\', \'index.php?page_id=71&event_year=$matches[1]\',\'top\');
add_rewrite_rule( \'whats-on/([0-9]{4})/([0-9]{1,2})/?$\', \'index.php?page_id=71&event_year=$matches[1]&event_month=$matches[2]\',\'top\');
add_rewrite_rule( \'whats-on/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$\', \'index.php?page_id=71&event_year=$matches[1]&event_month=$matches[2]&event_day=$matches[3]\',\'top\');