AdvancedCustomFields / AdvancedCustomFields/acf
Registering field for block does not work
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
I created a block with acf_register_block_type which shows the block in editor which is complete fine. I did that this way,
//custom block with acf
function mab_register_acf_block_types() {
acf_register_block_type( [
'name' => 'blockquote',
'title' => __( 'Blockquote' ),
'description' => __( 'My blockquote block.' ),
'render_template' => dirname( file ) . '/blocks/blockquote/blockquote.php',
'category' => 'formatting',
'icon' => 'format-quote',
] );
}
if ( function_exists( 'acf_register_block_type' ) ) {
add_action( 'acf/init', 'mab_register_acf_block_types' );
}
But I wanted to register the field for this block which actually does not work.
The registration of field done this way
add_action('acf/init', function () {
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'group_1',
'title' => 'My Group',
'fields' => array (
array (
'key' => 'field_1',
'label' => 'Sub Title',
'name' => 'sub_title',
'type' => 'text',
'prefix' => '',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
)
),
'location' => array (
array (
array (
'param' => 'block',
'operator' => '==',
'value' => 'blockquote',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
));
endif;
});
If I set the location to something else like post_type , it is okay, which means the code for registering the field is working for post_type but if I set the location to block == 'blockquote', it's not working.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the acf_register_block_type and acf_add_local_field_group calls shown in the issue, using the acf/init entry point and the block location rule for blockquote. Compare the behavior with the working post_type location rule and verify whether the field appears for the registered block in the editor.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100