admin管理员组文章数量:1425865
I want to forward a link to another link but internally. I've set up the wordpress to show post links like this - / which only throws 404 error. However If you visit / (location instead of medical), it works. So I want to forward any url containing medical
to location
.
Thanks in advance for your help
I want to forward a link to another link but internally. I've set up the wordpress to show post links like this - https://asif.bzstage/medical/website/nyc/ which only throws 404 error. However If you visit https://asif.bzstage/location/website/nyc/ (location instead of medical), it works. So I want to forward any url containing medical
to location
.
Thanks in advance for your help
Share Improve this question asked May 24, 2019 at 18:52 Asifur RahmanAsifur Rahman 52 bronze badges 2 |1 Answer
Reset to default 0The code below should work for you as long as:
- Your CPT slug is
location
. - You don't have a custom
query_var
registered for your CPTlocation
. You probably don't have. Refer to https://codex.wordpress/Function_Reference/register_post_type#query_var for more information, it's very usefull, btw.
And I'm assuming the string nyc
is the slug of your single custom post.
function rewrite_medical_url() {
add_rewrite_rule( '^medical/[^/]+/([^/]+)/?', 'index.php?location=$matches[1]', 'top' );
}
add_action( 'init', 'rewrite_medical_url' );
Put the code in your functions.php file.
In order for the rewrite rule start taking effect you should visit Settings > Permalinks to flush your permalinks.
本文标签: permalinksInternal forward link with addrewriterule
版权声明:本文标题:permalinks - Internal forward link with add_rewrite_rule 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745459331a2659250.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
location
– Asifur Rahman Commented May 27, 2019 at 14:28