posts_pre_query
Filters the posts array before the query takes place.
Return a non-null value to bypass WordPress' default post queries.
Filtering functions that require pagination information are encouraged to set the found_posts 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.
Usage
add_filter( 'posts_pre_query', 'wp_kama_posts_pre_query_filter' ); /** * Function for `posts_pre_query` filter-hook. * * @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. * * @return WP_Post[]|int[]|null */ function wp_kama_posts_pre_query_filter( $posts ){ // filter... return $posts; }
- $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.
Changelog
Since 4.6.0 | Introduced. |
Where the hook is called
posts_pre_query
wp-includes/class-wp-query.php 3161
$this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) );