October 22, 2024
Chicago 12, Melborne City, USA
PHP

get_query_var returns wrong value


I create a rewrite rule with different params


add_rewrite_rule(
    '^shop/(\b(thanks)\b)/([0-9]+)/([0-9]+)$', 
    'index.php?pagename=shop&shop_endpoint=$matches[1]&ref=$matches[2]&key=$matches[3]', 
    'top'
);

add_filter('query_vars', function($vars){
    $vars[] = 'shop_endpoint';
    $vars[] = 'ref';
    $vars[] = 'key';
    return $vars;       
}, 10, 1);

I have the following url
https://www.example.com/shop/thanks/2956789/6212/

If I dump

get_query_var('schop_endpoint');
get_query_var('ref');
get_query_var('key');

the output is

  • thanks
  • thanks
  • thanks

and not

  • thanks
  • 2956789
  • 6212

I does not see the mistake who can help me a little?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video