Title: request
Published: April 25, 2014
Last modified: April 28, 2025

---

# apply_filters( ‘request’, array $query_vars )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/request/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/request/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/request/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/request/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/request/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/request/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/request/?output_format=md#wp--skip-link--target)

Filters the array of parsed query variables.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/request/?output_format=md#parameters)󠁿

 `$query_vars`array

The array of requested query variables.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/request/?output_format=md#more-information)󠁿

 * This filter is applied to the query variables that are passed to the default 
   main SQL query that drives your page’s content. It is applied after additional
   private query variables have been added in, and is one of the places you can 
   hook into to modify the query that will generate your list of posts (or pages)
   before the main query is executed and the database is actually accessed.
 * Use this hook within `functions.php` as an alternative way to alter the posts
   returned in your Main Loop (as an alternate to [query_posts()](https://developer.wordpress.org/reference/functions/query_posts/)).
   The advantage of using this filter is that it alters the SQL query before it 
   is executed, reducing the number of database calls.
 * While it probably goes without saying, attempts to use this hook from within 
   a template php page will not do anything, as the main query will have already
   executed at that point.
 * As Rarst [mentions](http://wordpress.stackexchange.com/questions/21341/alternative-to-query-posts-for-main-loop/21342#21342),
   this filter affects all default queries, including calls to the admin Dashboard.
   You must be extremely careful and test thoroughly to ensure that no other parts
   of the site break when you modify the query string.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/request/?output_format=md#source)󠁿

    ```php
    $this->query_vars = apply_filters( 'request', $this->query_vars );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp.php#L409)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp.php#L409-L409)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/request/?output_format=md#related)󠁿

| Used by | Description | 
| [WP::parse_request()](https://developer.wordpress.org/reference/classes/wp/parse_request/)`wp-includes/class-wp.php` |

Parses the request to find the correct WordPress query.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/request/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/request/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/request/?output_format=md#comment-content-4736)
 2.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/request/#comment-4736)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frequest%2F%23comment-4736)
    Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frequest%2F%23comment-4736)
 4. Example migrated from Codex:
 5. Example usage by scribu (reproduced with permission from [wordpress.stackexchange.com](http://wordpress.stackexchange.com/questions/21341/alternative-to-query-posts-for-main-loop/21378#21378)):
 6.     ```php
        add_filter( 'request', 'alter_the_query' );
    
        function alter_the_query( $request ) {
            $dummy_query = new WP_Query();  // the query isn't run if we don't pass any query vars
            $dummy_query->parse_query( $request );
    
            // this is the actual manipulation; do whatever you need here
            if ( $dummy_query->is_home() )
                $request['category_name'] = 'news';
    
            return $request;
        }
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frequest%2F%3Freplytocom%3D4736%23feedback-editor-4736)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frequest%2F)
before being able to contribute a note or feedback.