query_loop_block_query_vars
Filter HookDescription
Filters the arguments which will be passed to `WP_Query` for the Query Loop Block. Anything to this filter should be compatible with the `WP_Query` API to form the query context which will be passed down to the Query Loop Block's children. This can help, for example, to include additional settings or meta queries not directly supported by the core Query Loop Block, and extend its capabilities. Please note that this will only influence the query that will be rendered on the front-end. The editor preview is not affected by this filter. Also, worth noting that the editor preview uses the REST API, so, ideally, one should aim to provide attributes which are also compatible with the REST API, in order to be able to implement identical queries on both sides.Hook Information
File Location |
wp-includes/blocks.php
View on GitHub
|
Hook Type | Filter |
Line Number | 2809 |
Hook Parameters
Type | Name | Description |
---|---|---|
array
|
$query
|
Array containing parameters for `WP_Query` as parsed by the block context. |
WP_Block
|
$block
|
Block instance. |
int
|
$page
|
Current query's page. |
Usage Examples
Basic Usage
<?php
// Hook into query_loop_block_query_vars
add_filter('query_loop_block_query_vars', 'my_custom_filter', 10, 3);
function my_custom_filter($query, $block, $page) {
// Your custom filtering logic here
return $query;
}
Source Code Context
wp-includes/blocks.php:2809
- How this hook is used in WordPress core
<?php
2804 *
2805 * @param array $query Array containing parameters for `WP_Query` as parsed by the block context.
2806 * @param WP_Block $block Block instance.
2807 * @param int $page Current query's page.
2808 */
2809 return apply_filters( 'query_loop_block_query_vars', $query, $block, $page );
2810 }
2811
2812 /**
2813 * Helper function that returns the proper pagination arrow HTML for
2814 * `QueryPaginationNext` and `QueryPaginationPrevious` blocks based
PHP Documentation
<?php
/**
* Filters the arguments which will be passed to `WP_Query` for the Query Loop Block.
*
* Anything to this filter should be compatible with the `WP_Query` API to form
* the query context which will be passed down to the Query Loop Block's children.
* This can help, for example, to include additional settings or meta queries not
* directly supported by the core Query Loop Block, and extend its capabilities.
*
* Please note that this will only influence the query that will be rendered on the
* front-end. The editor preview is not affected by this filter. Also, worth noting
* that the editor preview uses the REST API, so, ideally, one should aim to provide
* attributes which are also compatible with the REST API, in order to be able to
* implement identical queries on both sides.
*
* @since 6.1.0
*
* @param array $query Array containing parameters for `WP_Query` as parsed by the block context.
* @param WP_Block $block Block instance.
* @param int $page Current query's page.
*/
Quick Info
- Hook Type: Filter
- Parameters: 3
- File: wp-includes/blocks.php
Related Hooks
Related hooks will be displayed here in future updates.