Home › Forums › Gutenberg › ACF Blocks – Need stable id › Reply To: ACF Blocks – Need stable id
For some reason, this is what I got working, at least for now:
block.json
{
"name": "acf/clb-custom-info-card",
"title": "Info Card",
"description": "A custom info card block.",
"style": [ "file:./clb_custom_info_card.css" ],
"category": "common",
"icon": "admin-comments",
"keywords": ["testimonial", "quote"],
"acf": {
"mode": "preview",
"renderTemplate": "clb_custom_info_card.php"
},
"align": "full",
"providesContext": {"acf/fields": "data"},
"attributes": {
"clb_custom_id": {
"type": "string",
"default": "1234abcd"
}
}
}
And then my acf/pre_save_block
filter:
add_filter(
'acf/pre_save_block',
function( $attributes ) {
//error_log('attributes');
error_log( print_r( $attributes, true ) );
// if ( empty( $attributes['clb_custom_id'] ) ) {
// $attributes['clb_custom_id'] = 'clb_custom_id-' . uniqid();
// }
if( !$attributes['clb_custom_id'] ) { $attributes['clb_custom_id'] = uniqid(); }
// if ( empty( $attributes['data']['clb_custom_id'] ) ) {
// $attributes['data']['clb_custom_id'] = 'clb_custom_id-' . uniqid();
// }
return $attributes;
}
);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.