admin管理员组文章数量:1130349
I'm stuck on rewriting my url. been searching for days hacking code together but to no avail - So looking for help now.
My url is:
/?type=newsletter
I want the URL to be:
("topic" is a custom taxonomy)
This post seemed the most concise but couldn't get it to work
Help getting this working would make my day.
I'm stuck on rewriting my url. been searching for days hacking code together but to no avail - So looking for help now.
My url is:
https://domainname/topic/ux-process/?type=newsletter
I want the URL to be:
https://domainname/topic/ux-process/type/newsletter
("topic" is a custom taxonomy)
This post seemed the most concise but couldn't get it to work
https://code.tutsplus/articles/custom-page-template-page-based-on-url-rewrite--wp-30564
Help getting this working would make my day.
Share Improve this question edited Nov 20, 2018 at 10:21 Max Stanworth asked Nov 19, 2018 at 21:33 Max StanworthMax Stanworth 32 bronze badges1 Answer
Reset to default 0You can use a rewrite endpoint for this.
The first step is to give your custom taxonomy an endpoint mask when you register the taxonomy:
$args = [
'rewrite' => [
'slug' => 'topic',
'ep_mask' => EP_CATEGORIES
],
// the rest of your args...
];
register_taxonomy( 'topic', array( 'post' ), $args );
The next step is to add the endpoint. This should be hooked to run on init, just like your taxonomy registration code.
add_rewrite_endpoint( 'type', EP_CATEGORIES );
Don't forget to flush rewrite rules after adding this code. The easiest way to do this is by visiting the Settings > Permalinks page.
You should now be able to add type/newsletter onto the end of your taxonomy links. To access the passed value, use get_query_var:
$type = get_query_var( 'type', false );
If the code currently expects to find type in $_GET['type'] and you can't change that, you can manually set that value before the code that tries to access it:
$_GET['type'] = get_query_var( 'type', false );
I'm stuck on rewriting my url. been searching for days hacking code together but to no avail - So looking for help now.
My url is:
/?type=newsletter
I want the URL to be:
("topic" is a custom taxonomy)
This post seemed the most concise but couldn't get it to work
Help getting this working would make my day.
I'm stuck on rewriting my url. been searching for days hacking code together but to no avail - So looking for help now.
My url is:
https://domainname/topic/ux-process/?type=newsletter
I want the URL to be:
https://domainname/topic/ux-process/type/newsletter
("topic" is a custom taxonomy)
This post seemed the most concise but couldn't get it to work
https://code.tutsplus/articles/custom-page-template-page-based-on-url-rewrite--wp-30564
Help getting this working would make my day.
Share Improve this question edited Nov 20, 2018 at 10:21 Max Stanworth asked Nov 19, 2018 at 21:33 Max StanworthMax Stanworth 32 bronze badges1 Answer
Reset to default 0You can use a rewrite endpoint for this.
The first step is to give your custom taxonomy an endpoint mask when you register the taxonomy:
$args = [
'rewrite' => [
'slug' => 'topic',
'ep_mask' => EP_CATEGORIES
],
// the rest of your args...
];
register_taxonomy( 'topic', array( 'post' ), $args );
The next step is to add the endpoint. This should be hooked to run on init, just like your taxonomy registration code.
add_rewrite_endpoint( 'type', EP_CATEGORIES );
Don't forget to flush rewrite rules after adding this code. The easiest way to do this is by visiting the Settings > Permalinks page.
You should now be able to add type/newsletter onto the end of your taxonomy links. To access the passed value, use get_query_var:
$type = get_query_var( 'type', false );
If the code currently expects to find type in $_GET['type'] and you can't change that, you can manually set that value before the code that tries to access it:
$_GET['type'] = get_query_var( 'type', false );
本文标签: url rewritingHow do I rewrite URL that has custom parameter
版权声明:本文标题:url rewriting - How do I rewrite URL that has custom parameter 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749166856a2326327.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论