Overview
Filter field objects for a specific block type.
Description
This filter is a block-specific version of acf/schema/block_field_objects. It allows you to modify field objects only for a specific block type without affecting other blocks.
The dynamic portion of the hook name, {block_name}, refers to the full block name (e.g., acf/recipe).
Changelog
- Added in version 6.8.0
Parameters
apply_filters( 'acf/schema/block_field_objects/block_name={block_name}', $field_objects, $block, $block_type, $post_id );
$field_objects(array|null) Field objects array from previous filters$block(array) The block props array$block_type(array) The registered block type settings$post_id(int) The post ID where the block appears
Return
(array|null) Modified field objects array.
Example
This example adds nutrition data to a recipe block.
/**
* Add nutrition schema to recipe block.
*
* @param array|null $field_objects The field objects array.
* @param array $block The block props.
* @param array $block_type The block type settings.
* @param int $post_id The post ID.
* @return array Modified field objects.
*/
function my_acf_schema_recipe_nutrition( $field_objects, $block, $block_type, $post_id ) {
if ( null === $field_objects ) {
$field_objects = array();
}
// Add nutrition fields with NutritionInformation qualified properties
if ( isset( $block['data']['calories'] ) ) {
$field_objects['calories'] = array(
'value' => $block['data']['calories'] . ' calories',
'schema_property' => 'NutritionInformation.calories',
'type' => 'text',
);
}
if ( isset( $block['data']['protein'] ) ) {
$field_objects['protein'] = array(
'value' => $block['data']['protein'] . ' g',
'schema_property' => 'NutritionInformation.proteinContent',
'type' => 'text',
);
}
return $field_objects;
}
add_filter( 'acf/schema/block_field_objects/block_name=acf/recipe', 'my_acf_schema_recipe_nutrition', 10, 4 );
Supercharge Your Website With Premium Features Using ACF PRO
Speed up your workflow and unlock features to better develop websites using ACF Blocks and Options Pages, with the Flexible Content, Repeater, Clone, Gallery Fields & More.