You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ACF自定义区块字段注册失败:无法关联字段组问题排查

问题解决:ACF自定义区块字段组不显示的问题

问题出在字段组的位置匹配值上。ACF注册的自定义区块,其完整标识格式为[prefix]/[block-name],默认前缀prefix为acf,所以你需要把字段组位置条件里的value从blockquote改成acf/blockquote。

修正后的字段组注册代码如下:

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' => 'acf/blockquote', // 此处为修改关键
                    ),
                ),
            ),
            'menu_order' => 0,
            'position' => 'normal',
            'style' => 'default',
            'label_placement' => 'top',
            'instruction_placement' => 'label',
            'hide_on_screen' => '',
        ));

    endif;
});

补充说明

如果注册区块时自定义了prefix参数,比如:

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',
    'prefix'          => 'mab', // 自定义前缀
] );

那么字段组位置条件的value就要对应改成mab/blockquote。

内容的提问来源于stack exchange,提问作者Mithu A Quayium

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 15:25:30