1

This is an odd problem that I have never run into before with WordPress.

I have a site, permalinks enabled.

The url can be http://mysite.com/page-name/?anyParamName=testing

then when I use print_r($_GET); or echo $_GET["anyParamName"] I get an empty array or nothing respectively.

A pure PHP file works fine so its not a server issue. Does WordPress do anything with rewiring the get params? Really puzzled by this.

  • Where are you putting print_r( $_GET ) etc? In a theme file? – Boone Gorges Mar 19 '12 at 19:01
  • I've tried it all over the page.php template file, even before the header. – wesbos Mar 19 '12 at 19:03
  • any code anywhere in WordPress might be doing $_GET = []; just for fun. – Joel M Jan 21 at 4:00
2

For custom parameters you should register them with WordPress:

add_action('init','wpse46108_register_param');
function wpse46108_register_param() { 
    global $wp; 
    $wp->add_query_var('anyParamName'); 
}

Then the value of 'anyParamName' can be found with get_query_var

$anyParamNameValue = get_query_var('anyParamName').
|improve this answer|||||
  • that shouldn't have anything to do with $_GET being empty.. – Joel M Jan 21 at 4:02
1

know that this is old question, but we can freely access any post/get parameters inside 'init' hook, (before WordPress changes it) and that is documented here, look:

add_action( 'init', 'process_post' );

function process_post() {
     if( isset( $_POST['unique_hidden_field'] ) ) {
          // process $_POST data here, read and modify as you wish
     }
}
|improve this answer|||||
0

n order to be able to add and work with your own custom query vars that you append to URLs (eg: "http://example.com/some_page/?my_var=foo" - for example using add_query_arg()) you need to add them to the public query variables available to WP_Query. These are built up when WP_Query instantiates, but fortunately are passed through a filter 'query_vars' before they are actually used to populate the $query_vars property of WP_Query.

So, to expose your new, custom query variable to WP_Query hook into the 'query_vars' filter, add your query variable to the $vars array that is passed by the filter, and remember to return the array as the output of your filter function. See below:

function add_query_vars_filter( $vars ) {
  $vars[] = "my_var";
  return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );

For further details please have a look https://codex.wordpress.org/Function_Reference/get_query_var

|improve this answer|||||
0

I had the same problem:

  1. the page I accessed had permalink /focus.
  2. the main folder had a child folder with the same name (focus).

The right page was loaded (not the folder), but the _GET parameters were empty. I renamed the folder (in the file system) and the _GET array is now getting as expected.

|improve this answer|||||
  • interesting, was not aware of this. – Joel M Jan 21 at 4:05

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.