apply_filters_ref_array( 'posts_pre_query', \WP_Post[]|int[]|null $posts, WP_Query $query )
- Since
- 4.6.0
Filters the posts array before the query takes place.
Description
Return a non-null value to bypass WordPress' default post queries.
Filtering functions that require pagination information are encouraged to set the found_posts and max_num_pages properties of the WP_Query object, passed to the filter by reference. If WP_Query does not perform a database query, it will not have enough information to generate these values itself.
Compatibility
- WordPress
- since 4.6.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Parameters
$posts\WP_Post[]|int[]|null- Return an array of post data to short-circuit WP's query, or null to allow WP to run its normal queries.
$queryWP_Query- The WP_Query instance (passed by reference).
Where this hook fires · 1
wp-includes/class-wp-query.php:3161WP_Query::get_posts()
Source code
<?php * @since 4.6.0 * * @param WP_Post[]|int[]|null $posts Return an array of post data to short-circuit WP's query, * or null to allow WP to run its normal queries. * @param WP_Query $query The WP_Query instance (passed by reference). */ $this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) ); /* * Ensure the ID database query is able to be cached. * * Random queries are expected to have unpredictable results and * cannot be cached. Note the space before `RAND` in the stringChangelog
Introduced in 4.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
- Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.