Title: Cannot set global variable in index.php
Last modified: August 20, 2016

---

# Cannot set global variable in index.php

 *  [blk784](https://wordpress.org/support/users/blk784/)
 * (@blk784)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/cannot-set-global-variable-in-indexphp/)
 * 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:
    [http://www.32bitsofwin.com/?sort=1](http://www.32bitsofwin.com/?sort=1).
   The following is what I have in my functions.php:
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * 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.

## Tags

 * [custom-query](https://wordpress.org/support/topic-tag/custom-query/)
 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [global](https://wordpress.org/support/topic-tag/global/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [blk784](https://wordpress.org/support/users/blk784/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/cannot-set-global-variable-in-indexphp/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
