hi!
I want to build a custom plugin that will both
– register new ACF fields (via acf_add_local_field_group() )
– register new Gutenblocks (via acf_register_block() )
The gutenberg block does render oke. (i see the header line)
But in “edit” mode for some reason the new fields dont appear in the new registered blocks.
Is it even possible? or i missed something here?
Some testcode here:
if ( function_exists( 'acf_add_local_field_group' ) ):
add_action( 'acf/init', 'my_acf_add_local_field_groups' );
function my_acf_add_local_field_groups() {
acf_add_local_field_group( array(
'key' => 'group_1',
'title' => 'Block: Podcast',
'fields' => array(
array(
'key' => 'field_1',
'label' => 'Testblock field',
'name' => 'testblock_field',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
),
),
'location' => array(
array(
array(
'param' => 'block',
'operator' => '==',
'value' => 'acf/test_block',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
'metabox_title' => '',
) );
}
add_action( 'acf/init', 'my_register_blocks' );
function my_register_blocks() {
// check function exists
if ( function_exists( 'acf_register_block' ) ) {
// register a testimonial block
acf_register_block( array(
'name' => 'test_block',
'title' => __( 'ACF TEST block plugin' ),
'description' => __( 'A test block.' ),
'render_callback' => 'my_acf_block_render_callback',
'category' => 'formatting',
'icon' => 'admin-comments',
'mode' => 'auto',
'keywords' => []
) );
}
}
endif;
function my_acf_block_render_callback( $block, $content = '', $is_preview = false ) {
/* print_r($block);
print_r($content); */
$headlinegt = get_field( 'podcast_link' );
?>
<section class="tp-text-onecolumn-gutenberg">
<div class="container">
<div class="row">
<div class="col-12">
<div class="headline-container">
<h2 class="headline">Testing header></h2>
<h2 class="headline"><?php echo $headlinegt; ?></h2>
</div>
</div>
</div>
</div>
</section>
<?php
}
Same issue here! I can register fields via ACF plugin UI, but not via acf_add_local_field_group function.
I found a bug and fix it.
YOu are not able to use underscore in block name when you set locations for acf_add_local_field_group
Instead just replace all underscore with simple score and it will work.
acf_register_block( [
‘name’ => ‘test_any’,
‘title’ => ‘Test’,
‘render_callback’ => function() {
?>
<h2>123</h2>
<?php
}
] );
acf_add_local_field_group(array(
‘key’ => ‘block_test’,
‘title’ => ‘Block Test’,
‘active’ => 1,
‘fields’ => array (
array (
‘key’ => ‘field_1’,
‘label’ => ‘Sub Title’,
‘name’ => ‘sub_title’,
‘type’ => ‘text’,
)
),
‘location’ => array (
array (
array (
‘param’ => ‘block’,
‘operator’ => ‘==’,
‘value’ => ‘acf/test-any’,
),
),
),
));
You must be logged in to reply to this topic.
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!
ποΈ Just one more day until the next session of ACF Chat Fridays! Make sure to register for the latest updates on whatβs coming in ACF 6.1!
— Advanced Custom Fields (@wp_acf) March 30, 2023
π Friday 31st March 3pm UTC
π Register here - https://t.co/3UtvQbDwNm pic.twitter.com/7xtEJakeQN
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.