前言
筛选 Bricks 动态数据选择器中可用的 ACF 字段组。允许你排除特定的字段组,使其不出现在构建器的动态数据下拉中。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/acf/filter_field_groups', function( $groups ) {
// Loop through groups and unset the one you want to hide
foreach ( $groups as $key => $group ) {
// Example: Hide field group with key 'group_60f1234567890'
if ( $group['key'] === 'group_60f1234567890' ) {
unset( $groups[ $key ] );
}
}
return $groups;
} );
参数
$groups(array):通过 acf_get_field_groups() 检索到的 ACF 字段组数组。
示例代码
筛选返回值
add_filter( 'bricks/acf/filter_field_groups', function( $groups ) {
// Loop through groups and unset the one you want to hide
foreach ( $groups as $key => $group ) {
// Example: Hide field group with key 'group_60f1234567890'
if ( $group['key'] === 'group_60f1234567890' ) {
unset( $groups[ $key ] );
}
}
return $groups;
} );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/acf/filter_field_groups', function( $value, $groups ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。