Overview
Filter field objects before processing for a block.
Description
This filter allows you to modify or replace the field objects that are processed for JSON-LD output on ACF blocks. Return a non-null value to override the default field retrieval.
Changelog
- Added in version 6.8.0
Parameters
apply_filters( 'acf/schema/block_field_objects', $field_objects, $block, $block_type, $post_id );
$field_objects(array|null) Field objects array, or null to use default retrieval$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, or null to use default behavior.
Example
This example adds computed fields to a recipe block.
/**
* Add computed fields to recipe block JSON-LD.
*
* @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_block_fields( $field_objects, $block, $block_type, $post_id ) {
if ( $block['name'] !== 'acf/recipe' ) {
return $field_objects;
}
if ( null === $field_objects ) {
$field_objects = array();
}
// Calculate total time from block data
$prep_time = $block['data']['prep_time'] ?? 0;
$cook_time = $block['data']['cook_time'] ?? 0;
$field_objects['total_time'] = array(
'value' => $prep_time + $cook_time,
'schema_property' => 'totalTime',
'type' => 'number',
);
return $field_objects;
}
add_filter( 'acf/schema/block_field_objects', 'my_acf_schema_recipe_block_fields', 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.
Related
- Filters: acf/schema/block_field_objects/block_name={block_name}
- Filters: acf/schema/block_jsonld_enabled
- Filters: acf/schema/data
- Filters: acf/update_value
- Features: Structured Data for ACF Blocks