Title: Pass array to query_vars
Last modified: August 19, 2016

---

# Pass array to query_vars

 *  [wdm](https://wordpress.org/support/users/wdm/)
 * (@wdm)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/pass-array-to-query_vars/)
 * When adding an array to the global query variables with the `query_vars` hook,
   it is always flattened to the string ‘Array’.
 * I remember seeing a ticket on trac about this, but now I can’t seem to find it.
 * Can anyone shed any light, is there a workaround?
 *     ```
       ["query_vars"]=>
         array(1) {
           ["multi-cat"]=>
           string(5) "Array"
        }
       ```
   
 * **Update:** There’s [a ticket here](http://core.trac.wordpress.org/ticket/3891)
   that explains all values are cast as strings for security.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [wdm](https://wordpress.org/support/users/wdm/)
 * (@wdm)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/pass-array-to-query_vars/#post-1497001)
 * Here is the code:
 *     ```
       function add_query_vars($query_vars) {
         $query_vars[] = 'multi-cat';
         return $query_vars;
       }
       ```
   
 * With the url `blog.com/?multi-cat[]=6&multi-cat[]=10`
 * (GET vars come from a multiple category widget I’m working on, the selects are
   each named ‘multi-cat[]’ to create an array of category IDs).
 *     ```
       function parse_query_vars($query) {
         var_dump($query);
       }
       ```
   
 * The resulting var_dump shows the array is recognised, but cast to a string:
 *     ```
       ["query_vars"]=>
         array(1) {
           ["multi-cat"]=>
           string(5) "Array"
        }
       ```
   
 *  Thread Starter [wdm](https://wordpress.org/support/users/wdm/)
 * (@wdm)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/pass-array-to-query_vars/#post-1497004)
 * There is a kind-of workaround, by explicitly adding the `query_vars` from `$_GET`:
 *     ```
       function parse_query_vars($query) {
   
         if ( isset($_GET['multi-cat']) ) {
   
           $query->query_vars['multi-cat'] = $_GET['multi-cat'];
   
           var_dump($query);
   
         }
   
       }
       ```
   
 * The var_dump now reports:
 *     ```
       ["query_vars"]=>
         array(1) {
           ["multi-cat"]=>
           array(2) {
             [0]=>
             string(1) "6"
             [1]=>
             string(2) "10"
           }
         }
       ```
   
 * Unfortunately custom rewrite rules don’t seem to work with this method.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Pass array to query_vars’ is closed to new replies.

 * 2 replies
 * 1 participant
 * Last reply from: [wdm](https://wordpress.org/support/users/wdm/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/pass-array-to-query_vars/#post-1497004)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
