request WordPress Filter Hook

The request Wordpress hook is one of the most powerful tools available to developers. It allows you to modify the behavior of Wordpress itself, and extend it in ways that would otherwise be impossible. In this article, we'll explore what the request Wordpress hook is, and how you can use it to your advantage.

apply_filters( 'request', array $query_vars ) #

Filters the array of parsed query variables.


Parameters

$query_vars

(array)The array of requested query variables.


Top ↑

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()). 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, 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.

Top ↑

Source

File: wp-includes/class-wp.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.