AdvancedCustomFields / acf

Advanced Custom Fields
http://advancedcustomfields.com/
823 stars 168 forks source link

Registering field for block does not work #844

Open mithublue opened 1 year ago

mithublue commented 1 year ago

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.

CreativeDive commented 1 year ago

It seems you missed the block prefix here:

"param": "block",
"operator": "==",
"value": "acf\/blockquote"