posts_request WordPress Filter Hook

The posts_request hook is used to modify the SQL query that WordPress uses to fetch posts from the database. This hook can be used to alter the query based on various parameters, such as the post type or author.

apply_filters_ref_array( 'posts_request', string $request, WP_Query $query ) #

Filters the completed SQL query before sending.


Parameters

$request

(string)The complete SQL query.

$query

(WP_Query)The WP_Query instance (passed by reference).


Top ↑

More Information

The input of this filter is the post request SQL, something like the following:

SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN wp_posts AS p2 ON ( wp_posts.post_parent = p2.ID ) WHERE 1=1 AND wp_posts.ID IN ( 3, 632 ) AND wp_posts.post_type != 'revision' AND ( ( wp_posts.post_status = 'publish' ) OR ( wp_posts.post_status = 'inherit' AND ( p2.post_status = 'publish' ) ) ) ORDER BY wp_posts.post_date DESC LIMIT 0, 20


Top ↑

Source

File: wp-includes/class-wp-query.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
2.0.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.

Show More