Bricks 中文文档:bricks/query_filters_indexer/post/wcField

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

📄 原始资料  |  展开查看原始 JSON(bricks-query_filters_indexer-post-wcField.json)
{
  "name": "bricks/query_filters_indexer/post/wcField",
  "kind": "filter",
  "url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-query_filters_indexer-post-wcfield/",
  "scraped_at": "2026-08-29",
  "hook_name": "bricks/query_filters_indexer/post/wcField",
  "description": {
    "en": "A specialized hook for the Query Filters Indexer to generate index rows for WooCommerce product fields (like price, stock status, rating) when processing a filter job.",
    "zh": "Query Filters Indexer 的专门钩子,用于在处理筛选任务时为 WooCommerce 产品字段(如价格、库存状态、评分)生成索引行。"
  },
  "parameters": [
    {
      "name": "rows",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "Array of index rows to be inserted. Default is [] .",
        "zh": "将被插入的索引行数组。默认为 []。"
      }
    },
    {
      "name": "post",
      "type": "WP_Post|int",
      "type_zh": null,
      "description": {
        "en": "The product object or ID being indexed.",
        "zh": "正在被索引的产品对象或 ID。"
      }
    },
    {
      "name": "filter_id",
      "type": "string",
      "type_zh": null,
      "description": {
        "en": "The ID of the filter element.",
        "zh": "筛选元素的 ID。"
      }
    },
    {
      "name": "filter_settings",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "The settings of the filter element.",
        "zh": "筛选元素的设置。"
      }
    }
  ],
  "example_usage": "add_filter( 'bricks/query_filters_indexer/post/wcField', function( $rows, $post, $filter_id, $filter_settings ) {\n    // This filter is typically used internally by Bricks to handle WooCommerce fields.\n    // However, you could hook into it to index custom WooCommerce product data via the 'wcField' source.\n\n\n    // Check if indexing a specific custom WC field\n    if ( isset( $filter_settings['sourceFieldType'] ) && $filter_settings['sourceFieldType'] === 'my_custom_wc_field' ) {\n        // ... generate and return rows ...\n    }\n\n\n    return $rows;\n}, 10, 4 );"
}

前言

Query Filters Indexer 的专门钩子,用于在处理筛选任务时为 WooCommerce 产品字段(如价格、库存状态、评分)生成索引行。

用法

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

add_filter( 'bricks/query_filters_indexer/post/wcField', function( $rows, $post, $filter_id, $filter_settings ) {
    // This filter is typically used internally by Bricks to handle WooCommerce fields.
    // However, you could hook into it to index custom WooCommerce product data via the 'wcField' source.


    // Check if indexing a specific custom WC field
    if ( isset( $filter_settings['sourceFieldType'] ) && $filter_settings['sourceFieldType'] === 'my_custom_wc_field' ) {
        // ... generate and return rows ...
    }


    return $rows;
}, 10, 4 );

参数

  • $rows (array):将被插入的索引行数组。默认为 []。
  • $post (WP_Post|int):正在被索引的产品对象或 ID。
  • $filter_id (string):筛选元素的 ID。
  • $filter_settings (array):筛选元素的设置。

示例代码

筛选返回值

add_filter( 'bricks/query_filters_indexer/post/wcField', function( $rows, $post, $filter_id, $filter_settings ) {
    // This filter is typically used internally by Bricks to handle WooCommerce fields.
    // However, you could hook into it to index custom WooCommerce product data via the 'wcField' source.


    // Check if indexing a specific custom WC field
    if ( isset( $filter_settings['sourceFieldType'] ) && $filter_settings['sourceFieldType'] === 'my_custom_wc_field' ) {
        // ... generate and return rows ...
    }


    return $rows;
}, 10, 4 );

根据条件短路返回原值

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

add_filter( 'bricks/query_filters_indexer/post/wcField', function( $value, $rows ) {
    if ( is_admin() ) { return $value; }
    // TODO: custom logic here
    return $value;
} );

补充说明

更多细节可参考 官方文档