Bricks 中文文档:bricks/database/get_all_templates_by_type/after_query

📄 原始资料  |  展开查看原始 JSON(bricks-database-get_all_templates_by_type-after_query.json){ “name”: “bricks/database/get_all_templates_by_type/after_query”, “kind”: “action”, “url”: “https://academy.bricksbuilder.io/developer/hooks/actions/bricks-database-get_all_templates_by_type-after_query/”, “…

📄 原始资料  |  展开查看原始 JSON(bricks-database-get_all_templates_by_type-after_query.json)
{
  "name": "bricks/database/get_all_templates_by_type/after_query",
  "kind": "action",
  "url": "https://academy.bricksbuilder.io/developer/hooks/actions/bricks-database-get_all_templates_by_type-after_query/",
  "scraped_at": "2026-08-29",
  "hook_name": "bricks/database/get_all_templates_by_type/after_query",
  "description": {
    "en": "Runs after Bricks performs the uncached get_posts() query for all published Bricks templates. Use it to restore integration query context after Bricks has fetched template IDs. This action does not run when Bricks returns templates from object cache or the in-memory Database::$all_templates cache.",
    "zh": "Bricks 对所有已发布的 Bricks 模板执行未缓存的 get_posts() 查询之后触发。用于在 Bricks 抓取完模板 ID 之后恢复集成查询上下文。当 Bricks 从对象缓存或内存中的 Database::$all_templates 缓存返回模板时,此动作不会运行。"
  },
  "parameters": [
    {
      "name": "template_ids",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "Template IDs returned by the query.",
        "zh": "查询返回的模板 ID。"
      }
    },
    {
      "name": "args",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "The query arguments used to fetch templates.",
        "zh": "用于获取模板的查询参数。"
      }
    }
  ],
  "example_usage": "add_action( 'bricks/database/get_all_templates_by_type/after_query', function( $template_ids, $args ) {\n    // Restore custom query or language context here.\n}, 10, 2 );"
}

前言

Bricks 对所有已发布的 Bricks 模板执行未缓存的 get_posts() 查询之后触发。用于在 Bricks 抓取完模板 ID 之后恢复集成查询上下文。当 Bricks 从对象缓存或内存中的 Database::$all_templates 缓存返回模板时,此动作不会运行。

用法

将代码加入子主题的 functions.php

add_action( 'bricks/database/get_all_templates_by_type/after_query', function( $template_ids, $args ) {
    // Restore custom query or language context here.
}, 10, 2 );

参数

  • $template_ids (array):查询返回的模板 ID。
  • $args (array):用于获取模板的查询参数。

示例代码

官方示例用法

add_action( 'bricks/database/get_all_templates_by_type/after_query', function( $template_ids, $args ) {
    // Restore custom query or language context here.
}, 10, 2 );

根据条件短路返回原值

根据条件跳过或修改返回值:

add_filter( 'bricks/database/get_all_templates_by_type/after_query', function( $value, $template_ids ) {
    if ( is_admin() ) { return $value; }
    // TODO: custom logic here
    return $value;
} );

补充说明

更多细节可参考 官方文档