📄 原始资料 | 展开查看原始 JSON(bricks-get_templates-query_after.json){ “name”: “bricks/get_templates/query_after”, “kind”: “action”, “url”: “https://academy.bricksbuilder.io/developer/hooks/actions/bricks-get_templates-query_after/”, “scraped_at”: “2026-08-29”, “hook_name”: “bricks/get_templates/q…
📄 原始资料 | 展开查看原始 JSON(bricks-get_templates-query_after.json)
{
"name": "bricks/get_templates/query_after",
"kind": "action",
"url": "https://academy.bricksbuilder.io/developer/hooks/actions/bricks-get_templates-query_after/",
"scraped_at": "2026-08-29",
"hook_name": "bricks/get_templates/query_after",
"description": {
"en": "Runs after Bricks performs the uncached WP_Query inside Templates::get_templates_query() . Use it to restore integration context after the internal template query has run. This action does not run when Bricks returns the template query from object cache.",
"zh": "Bricks 在 Templates::get_templates_query() 中执行未缓存的 WP_Query 之后触发。用于在内部模板查询运行完毕后恢复集成上下文。当 Bricks 从对象缓存返回模板查询结果时,此动作不会运行。"
},
"parameters": [
{
"name": "query",
"type": "WP_Query",
"type_zh": null,
"description": {
"en": "The template query object.",
"zh": "模板查询对象。"
}
},
{
"name": "merged_args",
"type": "array",
"type_zh": null,
"description": {
"en": "The query arguments after Bricks merges custom and default values.",
"zh": "Bricks 合并自定义值和默认值之后的查询参数。"
}
}
],
"example_usage": "add_action( 'bricks/get_templates/query_after', function( $query, $merged_args ) {\n // Restore custom query context after template lookup.\n}, 10, 2 );"
}
前言
Bricks 在 Templates::get_templates_query() 中执行未缓存的 WP_Query 之后触发。用于在内部模板查询运行完毕后恢复集成上下文。当 Bricks 从对象缓存返回模板查询结果时,此动作不会运行。
用法
将代码加入子主题的 functions.php:
add_action( 'bricks/get_templates/query_after', function( $query, $merged_args ) {
// Restore custom query context after template lookup.
}, 10, 2 );
参数
$query (WP_Query):模板查询对象。
$merged_args (array):Bricks 合并自定义值和默认值之后的查询参数。
示例代码
官方示例用法
add_action( 'bricks/get_templates/query_after', function( $query, $merged_args ) {
// Restore custom query context after template lookup.
}, 10, 2 );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/get_templates/query_after', function( $value, $query ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。