admin管理员组文章数量:1130349
A specific post on my website has a shortcode that uses a parameter called "query" to produce its content. So, this is an example of a working URL:
"my-post" is the permalink of the post and the page is using the "query" param correctly.
However, we need to change this URL to a friendly one like and then I was trying to use the add_rewrite_rule like this:
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');
When I try to access the friendly URL, I'm redirected to successfully, but the query param is null ($_GET["query"] = null).
I also tried making use of add_rewrite_tag to register "query", but with no success.
If anyone has some light to shed it'd be more than appreciated.
A specific post on my website has a shortcode that uses a parameter called "query" to produce its content. So, this is an example of a working URL:
https://example/my-post?query=980
"my-post" is the permalink of the post and the page is using the "query" param correctly.
However, we need to change this URL to a friendly one like https://example/something-here/980 and then I was trying to use the add_rewrite_rule like this:
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');
When I try to access the friendly URL, I'm redirected to https://example/my-post successfully, but the query param is null ($_GET["query"] = null).
I also tried making use of add_rewrite_tag to register "query", but with no success.
If anyone has some light to shed it'd be more than appreciated.
Share Improve this question asked Nov 8, 2018 at 18:33 Adriano CastroAdriano Castro 1991 silver badge7 bronze badges1 Answer
Reset to default 2It sounds like the plugin expects there to be a get param.
Your rewrite-rule is removing the get-param before it can be used by the plugin.
If the plugin hasn't been updated for a long time (it's abandonware) then you can go through the plugin and replace the get-param with the portion of the url which would have been the get-param. Just make sure to prevent the plugin from updating after you've made your edits.
If you add the following
function custom_add_rewrite_rules() {
add_rewrite_tag('%query%','([^&]+)');
add_rewrite_rule(
'^something-here/([\d]+)$',
'index.php?p=10219&query=$matches[1]',
'top'
);
}
add_action('init', 'custom_add_rewrite_rules');
& then replace
$_GET['query'] &/or $_REQUEST['query] with get_query_var( 'query' ) in the plugin you've described, that should be enough to do the trick.
Stephen Harris sums it up nicely in the answer here
A specific post on my website has a shortcode that uses a parameter called "query" to produce its content. So, this is an example of a working URL:
"my-post" is the permalink of the post and the page is using the "query" param correctly.
However, we need to change this URL to a friendly one like and then I was trying to use the add_rewrite_rule like this:
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');
When I try to access the friendly URL, I'm redirected to successfully, but the query param is null ($_GET["query"] = null).
I also tried making use of add_rewrite_tag to register "query", but with no success.
If anyone has some light to shed it'd be more than appreciated.
A specific post on my website has a shortcode that uses a parameter called "query" to produce its content. So, this is an example of a working URL:
https://example/my-post?query=980
"my-post" is the permalink of the post and the page is using the "query" param correctly.
However, we need to change this URL to a friendly one like https://example/something-here/980 and then I was trying to use the add_rewrite_rule like this:
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');
When I try to access the friendly URL, I'm redirected to https://example/my-post successfully, but the query param is null ($_GET["query"] = null).
I also tried making use of add_rewrite_tag to register "query", but with no success.
If anyone has some light to shed it'd be more than appreciated.
Share Improve this question asked Nov 8, 2018 at 18:33 Adriano CastroAdriano Castro 1991 silver badge7 bronze badges1 Answer
Reset to default 2It sounds like the plugin expects there to be a get param.
Your rewrite-rule is removing the get-param before it can be used by the plugin.
If the plugin hasn't been updated for a long time (it's abandonware) then you can go through the plugin and replace the get-param with the portion of the url which would have been the get-param. Just make sure to prevent the plugin from updating after you've made your edits.
If you add the following
function custom_add_rewrite_rules() {
add_rewrite_tag('%query%','([^&]+)');
add_rewrite_rule(
'^something-here/([\d]+)$',
'index.php?p=10219&query=$matches[1]',
'top'
);
}
add_action('init', 'custom_add_rewrite_rules');
& then replace
$_GET['query'] &/or $_REQUEST['query] with get_query_var( 'query' ) in the plugin you've described, that should be enough to do the trick.
Stephen Harris sums it up nicely in the answer here
本文标签: url rewritingaddrewriterule ignoring other params than the quotpquot param
版权声明:本文标题:url rewriting - add_rewrite_rule ignoring other params than the "p" param 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749196526a2331072.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论