0

I am using a plugin (directories). If I filter directories I get something like this

/?filter_field_age%5B%5D=35&filter_field_regions%5B%5D=America

I want to get "35" and "America" to appear on page as text.

I used

function UTMParam( $atts ) {  
    extract( shortcode_atts( array(
        'param' => 'param',
    ), $atts ) );
    return $_GET[$param];  
}
add_shortcode('UTMParam', 'UTMParam'); 

and

[UTMParam param='filter_field_age'] [UTMParam param='filter_field_regions']

But its not working....any idea????

nealio82
  • 2,611
  • 1
  • 17
  • 19
Fraz
  • 1
  • 1

1 Answers1

0

You can use parse_str, but you'll have to strip the /? first :

$str = '/?filter_field_age%5B%5D=35&filter_field_regions%5B%5D=America';
$query = parse_url($str, PHP_URL_QUERY);
parse_str($query, $output);
print_r($output);

Result :

[
  'filter_field_age' => [
      0 => '35',
  ],
  'filter_field_regions' => [
      0 => 'America',
  ],
]
Louis Charette
  • 1,325
  • 1
  • 10
  • 34
  • Thanks for your help. BUT as I am not good in php. I tried what you suggested but it did not work. Let me clarify.... the query filter_field_age%5B%5D=35&filter_field_regions%5B%5D=America' is a result of filter, so every time a user changes filter the results also changes. – Fraz Jan 16 '20 at 20:28
  • So your issue is getting `$str`, or updating the result? Unless it's a wordpress specific issue... – Louis Charette Jan 16 '20 at 20:31
  • my goal is to show the $str (whatever filtered result is in url after "filter_field_age%5B%5D")....to a text on page or form field using short code..and yes its a wordpress site – Fraz Jan 16 '20 at 20:49