Get url param no longer works when using add_rewrite_rule

Question

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&regionparam=$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&regionparam=$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?

0
, bdk 3 years 2020-04-03T08:50:55-05:00 0 Answers 80 views 0

Leave an answer

Browse
Browse