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? Mar 19, 2012 at 19:01
  • I've tried it all over the page.php template file, even before the header.
    – wesbos
    Mar 19, 2012 at 19:03
  • any code anywhere in WordPress might be doing $_GET = []; just for fun.
    – Joel M
    Jan 21, 2020 at 4:00

4 Answers 4


For custom parameters you should register them with WordPress:

function wpse46108_register_param() { 
    global $wp; 

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

$anyParamNameValue = get_query_var('anyParamName').
  • that shouldn't have anything to do with $_GET being empty..
    – Joel M
    Jan 21, 2020 at 4:02
  • True, but it might extract the value before $_GET is emptied by a plug-in/theme (assuming that' is what's happening). Apr 24, 2020 at 19:07
  • this answer is misleading and might be construed to say this is how URL params are supposed to work in WordPress, which is not the case
    – Tom J Nowell
    Jan 17 at 17:53

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

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


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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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