Bricks 中文文档:bricks/get_templates/query_vars

标签TAGS: 

📄 原始资料  |  展开查看原始 JSON(bricks-get_templates-query_vars.json){ “name”: “bricks/get_templates/query_vars”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/bricks-get_templates-query_vars/”, “scraped_at”: “2026-08-29”, “hook_name”: “bricks/get_templates/quer…

📄 原始资料  |  展开查看原始 JSON(bricks-get_templates-query_vars.json)
{
  "name": "bricks/get_templates/query_vars",
  "kind": "filter",
  "url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-get_templates-query_vars/",
  "scraped_at": "2026-08-29",
  "hook_name": "bricks/get_templates/query_vars",
  "description": {
    "en": "Filters the query arguments used by Templates::get_templates_query() to retrieve Bricks templates. This allows you to customize which templates are fetched, for example, to support multilingual plugins or custom filtering.",
    "zh": "此筛选器允许你向“媒体库”面板添加新尺寸。"
  },
  "parameters": [
    {
      "name": "query_vars",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "Array of arguments passed to WP_Query .",
        "zh": "传递给 WP_Query 的参数数组。"
      }
    }
  ],
  "example_usage": "add_filter( 'bricks/get_templates/query_vars', function( $query_vars ) {\n    // Example: Exclude templates with a specific meta key\n    $query_vars['meta_query'][] = [\n        'key'     => 'my_exclude_key',\n        'compare' => 'NOT EXISTS',\n    ];\n\n\n    return $query_vars;\n} );"
}

前言

此筛选器允许你向“媒体库”面板添加新尺寸。

用法

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

add_filter( 'bricks/get_templates/query_vars', function( $query_vars ) {
    // Example: Exclude templates with a specific meta key
    $query_vars['meta_query'][] = [
        'key'     => 'my_exclude_key',
        'compare' => 'NOT EXISTS',
    ];


    return $query_vars;
} );

参数

  • $query_vars (array):传递给 WP_Query 的参数数组。

示例代码

筛选返回值

add_filter( 'bricks/get_templates/query_vars', function( $query_vars ) {
    // Example: Exclude templates with a specific meta key
    $query_vars['meta_query'][] = [
        'key'     => 'my_exclude_key',
        'compare' => 'NOT EXISTS',
    ];


    return $query_vars;
} );

根据条件短路返回原值

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

add_filter( 'bricks/get_templates/query_vars', function( $value, $query_vars ) {
    if ( is_admin() ) { return $value; }
    // TODO: custom logic here
    return $value;
} );

补充说明

更多细节可参考 官方文档