Skip to main content
added 218 characters in body
Source Link
Jebble
  • 837
  • 1
  • 6
  • 15

The global keyword imports the variable into the local scope, while $GLOBALS just grants you access to the variable.

To elaborate, if you use global $wp_the_query; you can use $wp_the_query inside the local scope without using the word global again. So basically global $wp_the_query can be compared to $wp_the_query = $GLOBALS['wp_the_query']

EDIT

I misread wp_query for wp_the_query so my answer isn't a complete answer to the question but still provides general information about the difference between global $variable and $GLOBALS['variable']

The global keyword imports the variable into the local scope, while $GLOBALS just grants you access to the variable.

To elaborate, if you use global $wp_the_query; you can use $wp_the_query inside the local scope without using the word global again. So basically global $wp_the_query can be compared to $wp_the_query = $GLOBALS['wp_the_query']

The global keyword imports the variable into the local scope, while $GLOBALS just grants you access to the variable.

To elaborate, if you use global $wp_the_query; you can use $wp_the_query inside the local scope without using the word global again. So basically global $wp_the_query can be compared to $wp_the_query = $GLOBALS['wp_the_query']

EDIT

I misread wp_query for wp_the_query so my answer isn't a complete answer to the question but still provides general information about the difference between global $variable and $GLOBALS['variable']

Source Link
Jebble
  • 837
  • 1
  • 6
  • 15

The global keyword imports the variable into the local scope, while $GLOBALS just grants you access to the variable.

To elaborate, if you use global $wp_the_query; you can use $wp_the_query inside the local scope without using the word global again. So basically global $wp_the_query can be compared to $wp_the_query = $GLOBALS['wp_the_query']