📄 原始资料 | 展开查看原始 JSON(bricks-query_filters-custom_field_index_rows.json){ “name”: “bricks/query_filters/custom_field_index_rows”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/bricks-query_filters-custom_field_index_rows/”, “scraped_at”: “2026-08-29”, …
📄 原始资料 | 展开查看原始 JSON(bricks-query_filters-custom_field_index_rows.json)
{
"name": "bricks/query_filters/custom_field_index_rows",
"kind": "filter",
"url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-query_filters-custom_field_index_rows/",
"scraped_at": "2026-08-29",
"hook_name": "bricks/query_filters/custom_field_index_rows",
"description": {
"en": "Filters the index rows generated for a custom field in the Query Filters system. This allows providers (like ACF, Meta Box) or custom code to handle how complex field data is indexed for filtering.",
"zh": "筛选 Query Filters 系统中为自定义字段生成的索引行。允许 providers(如 ACF、Meta Box)或自定义代码处理复杂字段数据的索引方式以用于筛选。"
},
"parameters": [
{
"name": "rows",
"type": "array",
"type_zh": null,
"description": {
"en": "Array of index rows. Each row is an associative array representing a filterable value.",
"zh": "索引行数组。每行是一个表示可筛选值的关联数组。"
}
},
{
"name": "object_id",
"type": "int",
"type_zh": null,
"description": {
"en": "The ID of the object (post, term, user) being indexed.",
"zh": "正在被索引的对象(文章、术语、用户)ID。"
}
},
{
"name": "meta_key",
"type": "string",
"type_zh": null,
"description": {
"en": "The meta key of the custom field.",
"zh": "自定义字段的 meta key。"
}
},
{
"name": "provider",
"type": "string",
"type_zh": null,
"description": {
"en": "The data provider (e.g., acf , metabox ).",
"zh": "数据 provider(例如 acf、metabox)。"
}
},
{
"name": "object_type",
"type": "string",
"type_zh": null,
"description": {
"en": "The type of object ( post , term , user ).",
"zh": "对象类型(post、term、user)。"
}
}
],
"example_usage": "add_filter( 'bricks/query_filters/custom_field_index_rows', function( $rows, $object_id, $meta_key, $provider, $object_type ) {\n // Example: Index a custom serialized field\n if ( $meta_key === 'my_serialized_field' ) {\n $value = get_post_meta( $object_id, $meta_key, true );\n // ... parse value ...\n $rows[] = [\n 'filter_value' => 'parsed_value',\n 'filter_value_display' => 'Display Value',\n // ... other required fields ...\n ];\n }\n\n\n return $rows;\n}, 10, 5 );"
}
前言
筛选 Query Filters 系统中为自定义字段生成的索引行。允许 providers(如 ACF、Meta Box)或自定义代码处理复杂字段数据的索引方式以用于筛选。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/query_filters/custom_field_index_rows', function( $rows, $object_id, $meta_key, $provider, $object_type ) {
// Example: Index a custom serialized field
if ( $meta_key === 'my_serialized_field' ) {
$value = get_post_meta( $object_id, $meta_key, true );
// ... parse value ...
$rows[] = [
'filter_value' => 'parsed_value',
'filter_value_display' => 'Display Value',
// ... other required fields ...
];
}
return $rows;
}, 10, 5 );
参数
$rows (array):索引行数组。每行是一个表示可筛选值的关联数组。
$object_id (int):正在被索引的对象(文章、术语、用户)ID。
$meta_key (string):自定义字段的 meta key。
$provider (string):数据 provider(例如 acf、metabox)。
$object_type (string):对象类型(post、term、user)。
示例代码
筛选返回值
add_filter( 'bricks/query_filters/custom_field_index_rows', function( $rows, $object_id, $meta_key, $provider, $object_type ) {
// Example: Index a custom serialized field
if ( $meta_key === 'my_serialized_field' ) {
$value = get_post_meta( $object_id, $meta_key, true );
// ... parse value ...
$rows[] = [
'filter_value' => 'parsed_value',
'filter_value_display' => 'Display Value',
// ... other required fields ...
];
}
return $rows;
}, 10, 5 );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/query_filters/custom_field_index_rows', function( $value, $rows ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。