admin管理员组文章数量:1389187
I'm using WordPress admin to create a page (named get-region-page
), in which Pod shortcode is used to retrieve the URL parameter. For example:
[pods name="region" slug="{@get.regionparam}" field="region_name"]
With a redirection 301 to the URL /get-region-page®ionparam=$region_slug
, the Pod shortcode works fine.
The problem arrives when I need to create a rewrite rule for that page in functions.php
(with 1234
is the page ID for get-region-page
):
add_rewrite_rule('({some-custom-regex})/?$','index.php?page_id=1234®ionparam=$matches[1]','top');
...the parameter becomes null
. I can no longer retrieve the URL parameter.
But if I try this PHP code in the WordPress template of the page, the parameter is still there:
echo get_query_var('regionparam');
Remark, this one does not work either in the PHP template:
echo $_GET['regionparam'];
So I wonder if there is some equivalent Pod shortcode for get_query_var('regionparam')
for my first Pod shortcode to work again?
I'm using WordPress admin to create a page (named get-region-page
), in which Pod shortcode is used to retrieve the URL parameter. For example:
[pods name="region" slug="{@get.regionparam}" field="region_name"]
With a redirection 301 to the URL /get-region-page®ionparam=$region_slug
, the Pod shortcode works fine.
The problem arrives when I need to create a rewrite rule for that page in functions.php
(with 1234
is the page ID for get-region-page
):
add_rewrite_rule('({some-custom-regex})/?$','index.php?page_id=1234®ionparam=$matches[1]','top');
...the parameter becomes null
. I can no longer retrieve the URL parameter.
But if I try this PHP code in the WordPress template of the page, the parameter is still there:
echo get_query_var('regionparam');
Remark, this one does not work either in the PHP template:
echo $_GET['regionparam'];
So I wonder if there is some equivalent Pod shortcode for get_query_var('regionparam')
for my first Pod shortcode to work again?
2 Answers
Reset to default 0I don't know why my question was not well formatted and can not modify it. Here's the more readable one:
I'm using WP Admin DIVI builder to create a page (named get-region-page), in which Pod shortcut is used to retrieve the url param. For example:
[pods name="region" slug="{@get.regionparam}" field="region_name"]
which gives apparently the same result as using these in the php template of the page:
$_GET['regionparam']
With a redirection 301 to that page url: /get-region-page®ionparam=$region_slug, everything works fine, I can retrieve the url parameter. The problem arrives when I replace the 301 redirection with a rewrite rule for that page in functions.php (with 1234 the page id for get-region-page):
add_rewrite_rule('({some-custom-regex})/?$','index.php?page_id=1234®ionparam=$matches[1]','top');
...the parameter regionparam becomes null. Only this works:
get_query_var('regionparam');
but no longer this
$_GET['regionparam'];
So I wonder if there is any way I can retrieve that get_query_var('regionparam') for my first pod shortcut to rework again in DIVI builder? Thank you for your help!
I found the solution, rather a workaround for my problem.
The url parameter can still be retrieved by using $GLOBALS[ ‘any’ ]
thanks to this document: https://docs.pods.io/displaying-pods/magic-tags/special-magic-tags/.
So instead of using $_GET['any']
as in my previous shortcode:
[pods name="region" slug="{@get.regionparam}" field="region_name"]
I just replace it with $GLOBALS
:
[pods name="region" slug="{@globals.regionparam}" field="region_name"]
In order for the parameter regionparam
to be available as global, I needed to add this filter in functions.php
:
add_filter("query_vars", function( $vars ){
$vars[] = "regionparam";
$vars[] .= "otherParamsIfNeeded";
return $vars;
});
And in the other functions, I replace the old $_GET['regionparam']
by get_query_var('regionparam')
.
本文标签: url rewritingGet url param no longer works when using addrewriterule
版权声明:本文标题:url rewriting - Get url param no longer works when using add_rewrite_rule 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744601318a2615084.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论