bricks-global-queries
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRequires: Bricks 2.4+ with the Abilities API enabled
要求: 启用Abilities API的Bricks 2.4及以上版本
Update check
更新检查
Run first when filesystem tools are available:
bash
_BS_UPDATE_CHECK=""
for _CAND in "$HOME/.bricks/skills/bricks-skills/scripts/bricks-skills-update-check" "$PWD/scripts/bricks-skills-update-check" "$HOME/.claude/skills/bricks-skills/scripts/bricks-skills-update-check" "$HOME/.codex/skills/bricks-skills/scripts/bricks-skills-update-check"; do
[ -f "$_CAND" ] && _BS_UPDATE_CHECK="$_CAND" && break
done
[ -n "$_BS_UPDATE_CHECK" ] && sh "$_BS_UPDATE_CHECK" || trueIf it prints , load bricks-skills-update before continuing. If it prints , mention the new version and continue.
BRICKS_SKILLS_UPDATE_AVAILABLE <old> <new> <tag>BRICKS_SKILLS_JUST_UPDATED <old> <new>当文件系统工具可用时,首先运行以下命令:
bash
_BS_UPDATE_CHECK=""
for _CAND in "$HOME/.bricks/skills/bricks-skills/scripts/bricks-skills-update-check" "$PWD/scripts/bricks-skills-update-check" "$HOME/.claude/skills/bricks-skills/scripts/bricks-skills-update-check" "$HOME/.codex/skills/bricks-skills/scripts/bricks-skills-update-check"; do
[ -f "$_CAND" ] && _BS_UPDATE_CHECK="$_CAND" && break
done
[ -n "$_BS_UPDATE_CHECK" ] && sh "$_BS_UPDATE_CHECK" || true如果输出,请先加载bricks-skills-update再继续。如果输出,则提及新版本并继续。
BRICKS_SKILLS_UPDATE_AVAILABLE <旧版本> <新版本> <标签>BRICKS_SKILLS_JUST_UPDATED <旧版本> <新版本>Bricks: global queries (via MCP)
Bricks:全局查询(通过MCP)
A global query is a named, reusable query definition stored at the site level. Multiple loop/filter elements can reference the same global query by ID instead of duplicating args. Useful when the query is complex (ACF meta filters, taxonomy unions, custom SQL) and reused across templates.
Storage: (query rows with , , , and ) + (category rows with and for the builder UI grouping).
bricks_global_queriesidnamecategorysettingsbricks_global_queries_categoriesidname全局查询是存储在站点级别的命名可复用查询定义。多个循环/筛选元素可通过ID引用同一个全局查询,无需重复参数。当查询逻辑复杂(如ACF元数据筛选、分类联合、自定义SQL)且需要在多个模板中复用时,这一功能非常实用。
存储方式:(包含、、和的查询行) + (用于构建器UI分组的包含和的分类行)。
bricks_global_queriesidnamecategorysettingsbricks_global_queries_categoriesidnameAbilities
功能接口(Abilities)
- : summary rows plus category list.
bricks/list-global-queries - :
bricks/get-global-query. Full query object.{ queryId } - :
bricks/create-global-query. Returns{ label, category?, query }. The API accepts{ query }andlabel, then stores them in Bricks asqueryandname. The optionalsettingsis a category ID, not a label.category - :
bricks/update-global-query. If{ queryId, label?, category?, query? }is provided, it replaces the whole query settings object.query - :
bricks/delete-global-query. Does not unlink referencing elements: those keep the dangling id and fall back to their local query or render empty.{ queryId } - :
bricks/create-global-query-category. Returns{ name }.{ category } - :
bricks/delete-global-query-category. Queries in that category are kept and become uncategorized.{ categoryId }
- :返回查询摘要行及分类列表。
bricks/list-global-queries - :参数
bricks/get-global-query,返回完整的查询对象。{ queryId } - :参数
bricks/create-global-query,返回{ label, category?, query }。该API接受{ query }和label,并将其作为query和name存储在Bricks中。可选参数settings是分类ID,而非分类标签。category - :参数
bricks/update-global-query。如果提供{ queryId, label?, category?, query? },则会替换整个查询设置对象。query - :参数
bricks/delete-global-query。不会解除与引用元素的关联:这些元素会保留无效ID,并回退到本地查询或渲染为空。{ queryId } - :参数
bricks/create-global-query-category,返回{ name }。{ category } - :参数
bricks/delete-global-query-category。该分类下的查询会被保留,但变为未分类状态。{ categoryId }
Query shape
查询结构
Same shape as an inline query on a loop element:
{
objectType: "post", // "post" | "term" | "user"
postType: ["post"],
posts_per_page: 6,
orderby: "date",
order: "DESC",
meta_query: [ ... ],
tax_query: [ ... ]
}objectTypequeryposttermuserarrayapiposttermuserbricks/posts/query_varsbricks/terms/query_varsbricks/users/query_varsobjectTypeincludes/abilities/queries.php:123-142与循环元素上的内联查询结构相同:
{
objectType: "post", // "post" | "term" | "user"
postType: ["post"],
posts_per_page: 6,
orderby: "date",
order: "DESC",
meta_query: [ ... ],
tax_query: [ ... ]
}objectTypequeryposttermuserarrayapiposttermuserbricks/posts/query_varsbricks/terms/query_varsbricks/users/query_varsobjectTypeincludes/abilities/queries.php:123-142Binding to a loop
绑定到循环元素
An element consuming a global query stores its id in :
settings.query.idquery:
id: "abc123" // presence of this makes Bricks load the global query settings
# inline args are ignored when id points to a valid global queryWrite this through on the target element; the query runner resolves the id at render time.
bricks/update-element使用全局查询的元素会在中存储其ID:
settings.query.idquery:
id: "abc123" // 存在该ID时,Bricks会加载全局查询设置
# 当ID指向有效的全局查询时,内联参数会被忽略通过对目标元素调用来写入此配置;查询运行器会在渲染时解析ID。
bricks/update-elementCategories
分类
Categories are pure UI: they group queries in the builder's dropdown. Write shape:
bricks/update-global-query
queryId: abc123
category: "cat_abc"If you need a new category, call first and pass the returned category ID into or . Passing a new label as is wrong; the current schema expects a category ID.
bricks/create-global-query-categorycreate-global-queryupdate-global-querycategory分类仅用于UI:在构建器的下拉菜单中对查询进行分组。写入格式:
bricks/update-global-query
queryId: abc123
category: "cat_abc"如果需要新分类,请先调用,并将返回的分类ID传入或。传入新标签作为是错误的;当前架构要求传入分类ID。
bricks/create-global-query-categorycreate-global-queryupdate-global-querycategoryTool availability
工具可用性
If aability is not available as a direct tool: first check whether it is outside the fast path and call it throughbricks/*withmcp-adapter-execute-ability. If the dispatcher also rejects it, callability_name: "bricks/<name>"to check whether a site admin disabled it under Bricks > AI.bricks-list-ability-status
如果功能接口无法作为直接工具使用:首先检查它是否不在快速路径中,然后通过bricks/*调用它,参数为mcp-adapter-execute-ability。如果调度器也拒绝调用,请调用ability_name: "bricks/<name>"检查站点管理员是否在Bricks > AI下禁用了该功能。bricks-list-ability-status
Typical flow: reusable "Featured Products" query
典型流程:可复用的“精选产品”查询
bricks/create-global-query-category { name: "Shop" }
-> { category: { id: "cat_abc", name: "Shop" } }
bricks/create-global-query
label: "Featured Products"
category: "cat_abc"
query:
objectType: "post"
postType: ["product"]
posts_per_page: 8
meta_query:
- { key: "_featured", value: "yes" }
-> { query: { id: "fp_8h2", name: "Featured Products", category: "cat_abc", settings: {...} } }bricks/create-global-query-category { name: "Shop" }
-> { category: { id: "cat_abc", name: "Shop" } }
bricks/create-global-query
label: "Featured Products"
category: "cat_abc"
query:
objectType: "post"
postType: ["product"]
posts_per_page: 8
meta_query:
- { key: "_featured", value: "yes" }
-> { query: { id: "fp_8h2", name: "Featured Products", category: "cat_abc", settings: {...} } }Now bind it to an existing Products Loop element:
现在将其绑定到现有的产品循环元素:
bricks/update-element
postId: 42
elementId: "loop-xyz"
settings:
query:
id: "fp_8h2"
All future edits to "Featured Products" propagate to every element whose `settings.query.id` references that global query.bricks/update-element
postId: 42
elementId: "loop-xyz"
settings:
query:
id: "fp_8h2"
未来对“精选产品”查询的所有编辑都会同步到所有`settings.query.id`引用该全局查询的元素。Cross-context notes
跨上下文注意事项
- Global queries respect element-specific context. If the element lives in a single-post template, inside query filters still resolves to the current post: the global query is the args, not the context.
get_the_ID() - filter fires for global queries exactly as it does for inline ones. Match on the calling element id, not the query id, if you need to branch per-consumer.
bricks/posts/query_vars
- 全局查询会尊重元素特定的上下文。如果元素位于单篇文章模板中,查询筛选器内的仍会解析为当前文章:全局查询仅提供参数,而非上下文。
get_the_ID() - 钩子针对全局查询的触发方式与内联查询完全相同。如果需要根据使用方进行分支,请匹配调用元素的ID,而非查询ID。
bricks/posts/query_vars
Don't
注意事项
- Don't delete a global query without first replacing or clearing references. Query-list controls on elements silently fall back when the id is missing, and that's hard to spot in a big site.
- Don't embed element-specific context in a global query (e.g., a hard-coded post id). Use dynamic tags () or the
{post_id}hook so the query stays reusable.bricks/posts/query_vars - Do not treat the category field as load-bearing beyond UI organization. It is a category ID that points to a display label; it is not a permission or routing key.
- 请勿在未替换或清除引用的情况下删除全局查询。元素上的查询列表控件在ID缺失时会静默回退,这在大型站点中很难发现。
- 请勿在全局查询中嵌入元素特定的上下文(如硬编码的文章ID)。使用动态标签()或
{post_id}钩子,确保查询保持可复用性。bricks/posts/query_vars - 请勿将分类字段视为UI组织之外的关键功能。它是指向显示标签的分类ID,而非权限或路由键。