我网站上的一篇特定帖子有一个短代码,它使用一个名为“query”的参数来生成内容。这是一个工作URL的示例:
https://example.com/my-post?query=980
“我的帖子”是帖子的永久链接,页面正确使用了“query”参数。但是,我们需要将此URL更改为友好的URL,如https://example.com/something-here/980 然后我试着用add_rewrite_rule
像这样:
function custom_add_rewrite_rules() {
add_rewrite_rule(
\'^something-here/([\\d]+)$\',
\'index.php?p=10219&query=$matches[1]\',
\'top\'
);
}
add_action(\'init\', \'custom_add_rewrite_rules\');
当我尝试访问友好URL时,我会被重定向到https://example.com/my-post 成功,但query 参数为空($_GET["query"] = null
).我还试着利用add_rewrite_tag
注册“查询”,但没有成功。
如果有人能透露一些信息,我将不胜感激。