我在年得到了这个解决方案functions.php
, 感谢Wordpress官方文档:https://codex.wordpress.org/Rewrite_API/add_rewrite_rule
首先添加了自定义重写规则,如下所示:
function custom_rewrite_rule() {
add_rewrite_rule(
\'^agenda/([^/]*)/([^/]*)/?\',
\'index.php?page_id=10&agenda_id=$matches[1]&agenda_name=$matches[2]\',
\'top\' );
}
add_action( \'init\', \'custom_rewrite_rule\', 10, 0 );
然后需要添加以下内容:
function prefix_register_query_var( $vars ) {
$vars[] = \'agenda_id\';
$vars[] = \'agenda_name\';
return $vars;
}
add_filter( \'query_vars\', \'prefix_register_query_var\' );
现在URL的/agenda/1/event title工作起来很有魅力!并传递所需的变量。
PS: Remember to save the permalinks settings in the backend once again, or this code won\'t work!