admin管理员组文章数量:1122832
I am looking for a ReWrite rule or something to achieve this in WordPress:
/mycontent/events/slug_a
/mycontent/events/slug_b
/mycontent/events/slug_c
... should all lead to the page
/mycontent/events/
where I can us the slug as a variable to trigger an wp_query request.
How can I do that?
I am looking for a ReWrite rule or something to achieve this in WordPress:
/mycontent/events/slug_a
/mycontent/events/slug_b
/mycontent/events/slug_c
... should all lead to the page
/mycontent/events/
where I can us the slug as a variable to trigger an wp_query request.
How can I do that?
Share Improve this question edited Aug 20, 2024 at 21:28 wepli23 asked Aug 20, 2024 at 21:28 wepli23wepli23 113 bronze badges1 Answer
Reset to default 0First add the rewrite rule:
function wpse426504_add_rewrite() {
add_rewrite_rule( 'mycontent/events/([a-z0-9-]+)[/]?$', 'index.php?eventslug=$matches[1]', 'top' );
}
add_action( 'init', 'wpse426504_add_rewrite' );
function wpse426504_add_query_var( $query_vars ) {
$query_vars[] = 'eventslug';
return $query_vars;
} );
add_filter( 'query_vars', 'wpse426504_add_query_var' );
That's the basics of it. If you need to add a new template to handle displaying everything, you'd then hook to template_redirect
.
本文标签: url rewritingHow to write ReWrite Rule to cut URL
版权声明:本文标题:url rewriting - How to write ReWrite Rule to cut URL? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736297295a1929979.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论