Cannot set global variable in index.php
-
I am having problems setting a global variable in the index.php that I need to use to determine whether or not to use a custom query. I have add_filters in my functions.php and within each I check the value of a global variable to determine whether or not to use the custom query. I have the following code in the top of my index.php:
global $sort; if(isset($_GET['sort'])) { $sort = $_GET['sort']; } else { $sort = 1; }
The variable is not getting set even when I pass in a parameter through the url like so:
https://www.32bitsofwin.com/?sort=1. The following is what I have in my functions.php:[Code moderated as per the Forum Rules. Please use the pastebin]
Everything works fine as long as I set $sort in the functions.php so I know my sql query in my filter functions is working properly I just cant seem to get the global working right.
- The topic ‘Cannot set global variable in index.php’ is closed to new replies.