query_loop_block_query_vars хук-фильтрWP 6.1.0

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.

Использование

add_filter( 'query_loop_block_query_vars', 'wp_kama_query_loop_block_vars_filter', 10, 3 );

/**
 * Function for `query_loop_block_query_vars` filter-hook.
 * 
 * @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.
 *
 * @return array
 */
function wp_kama_query_loop_block_vars_filter( $query, $block, $page ){

	// filter...
	return $query;
}
$query(массив)
Array containing parameters for WP_Query as parsed by the block context.
$block(WP_Block)
Block instance.
$page(int)
Current query's page.

Список изменений

С версии 6.1.0 Введена.

Где вызывается хук

build_query_vars_from_query_block()
query_loop_block_query_vars
wp-includes/blocks.php 1369
return apply_filters( 'query_loop_block_query_vars', $query, $block, $page );

Где используется хук в WordPress

Использование не найдено.