📄 原始资料 | 展开查看原始 JSON(bricks-filter_element-before_set_data_source_from_custom_field.json){ “name”: “bricks/filter_element/before_set_data_source_from_custom_field”, “kind”: “action”, “url”: “https://academy.bricksbuilder.io/developer/hooks/actions/bricks-filter_element-before_set_data_so…
📄 原始资料 | 展开查看原始 JSON(bricks-filter_element-before_set_data_source_from_custom_field.json)
{
"name": "bricks/filter_element/before_set_data_source_from_custom_field",
"kind": "action",
"url": "https://academy.bricksbuilder.io/developer/hooks/actions/bricks-filter_element-before_set_data_source_from_custom_field/",
"scraped_at": "2026-08-29",
"hook_name": "bricks/filter_element/before_set_data_source_from_custom_field",
"description": {
"en": "Runs before setting the data source for a filter element that uses a custom field. This hook allows you to modify the filter element instance before the custom field data is processed.",
"zh": "在为使用自定义字段的筛选元素设置数据源之前触发。此钩子允许你在自定义字段数据被处理之前修改筛选元素实例。"
},
"parameters": [
{
"name": "filter_element",
"type": "Bricks\\Filter_Element",
"type_zh": null,
"description": {
"en": "The filter element instance.",
"zh": "筛选元素实例。"
}
}
],
"example_usage": "add_action( 'bricks/filter_element/before_set_data_source_from_custom_field', function( $filter_element ) {\n // You can access $filter_element properties here, for example:\n // $settings = $filter_element->settings;\n\n\n // Example: modify settings before processing\n // $filter_element->settings['customFieldKey'] = 'modified_key';\n} );"
}
前言
在为使用自定义字段的筛选元素设置数据源之前触发。此钩子允许你在自定义字段数据被处理之前修改筛选元素实例。
用法
将代码加入子主题的 functions.php:
add_action( 'bricks/filter_element/before_set_data_source_from_custom_field', function( $filter_element ) {
// You can access $filter_element properties here, for example:
// $settings = $filter_element->settings;
// Example: modify settings before processing
// $filter_element->settings['customFieldKey'] = 'modified_key';
} );
参数
$filter_element (Bricks\Filter_Element):筛选元素实例。
示例代码
官方示例用法
add_action( 'bricks/filter_element/before_set_data_source_from_custom_field', function( $filter_element ) {
// You can access $filter_element properties here, for example:
// $settings = $filter_element->settings;
// Example: modify settings before processing
// $filter_element->settings['customFieldKey'] = 'modified_key';
} );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/filter_element/before_set_data_source_from_custom_field', function( $value, $filter_element ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。