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
相关产品推荐
相关产品推荐

