1

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

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

0

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').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.