oke i give up. Even tried to do it the @wordpress way with edit.js etc.
Should be a simple thing but it looks imposible..
i want to reload an ACF block when i change an ACF metabox checkbox
Oke getting pretty close to a solution but can’t figure out how to trigger “rerender” on the acf block.
(function($, acf, wp){
const blockName = 'tatof/content-side';
const fieldKey = 'field_1234567890abc';
acf.addAction('ready', () => {
const field = acf.getField(fieldKey);
if (! field) return;
field.on('change', 'input, select, textarea, checkbox', () => {
const newVal = field.val();
// Push into WP data store
wp.data.dispatch('core/editor').editPost({
meta: { event_date: newVal }
});
// Update the block attribute
const { getBlocks } = wp.data.select('core/block-editor');
const { updateBlockAttributes } = wp.data.dispatch('core/block-editor');
getBlocks().forEach(block => {
if (block.name !== blockName) return;
updateBlockAttributes(block.clientId, { googleRev: newVal });
// Force ACF to re-render preview
const wrapper = document.querySelector('.wp-block[data-type="'+blockName+'"][data-block="'+block.clientId+'"]');
if (wrapper) {
acf.doAction(
'render_block_preview',
$(wrapper),
{
name: blockName,
attributes: block.attributes,
mode: 'preview'
}
);
}
});
});
});
})(jQuery, acf, wp.data);
It is like block bindings api but without the binding..
Just need to fire a update because my block gets its data from get_field(‘meta’,$postID);
Ah! Its always the little things 😉
Yes I did encouter that. Only got that problem with images, its important that you load them by ID.
Also check if all the Field keys are 100% correct. like my setup above.
I’ve got the same problem.
What is the status of this bug?
Anyone? simple yes/no answer is enough 🙂
Yes this would be amazing! Also place it in de sidebar per ACF field Group.
In that way we can create two Field groups:
1. Settings for the block
2. Content for the block
Right now im making a FAQ repeater (title,text,button). This has to be placed in the editor. But my standard cloned settings would be better in the sidebar.
This is not posible now.
Repeater:
'template' => array(
array('core/columns', array(), array(
array('core/column', array(), array(
array('core/paragraph', array(
'placeholder' => 'Intro tekst hier'
)),
array('tatof/button', array(
'data' => [
// Button one
'template_buttons_0_tb_button' => [
'title' => 'Voorbeeld knop',
'url' => '#',
'target' => ''
],
'_template_buttons_0_tb_button' => 'field_637e1739ba382',
'template_buttons_0_tb_color' => 'secondary',
'_template_buttons_0_tb_color' => 'field_637e1750ba383',
'template_buttons_0_tb_icon' => '',
'_template_buttons_0_tb_icon' => 'field_637e18cfba384',
// Button two
'template_buttons_1_tb_button' => [
'title' => 'Voorbeeld twee',
'url' => '#',
'target' => ''
],
'_template_buttons_1_tb_button' => 'field_637e1739ba382',
'template_buttons_1_tb_color' => 'primary',
'_template_buttons_1_tb_color' => 'field_637e1750ba383',
'template_buttons_1_tb_icon' => '',
'_template_buttons_1_tb_icon' => 'field_637e18cfba384',
'template_buttons' => 2,
'_template_buttons' => 'field_637e171dba381',
]
)),
)),
array('core/column', array(), array(
array('acf/tf-image', array()),
)),
)),
),
Got the solution 🙂
If you want to repeat an other button change 0 to 1
array('tatof/button', array(
'data' => [
'template_buttons_0_tb_button' => [
'title' => 'Button title',
'url' => '#',
'target' => ''
],
'_template_buttons_0_tb_button' => 'field_637e1739ba382',
'template_buttons_0_tb_color' => 'primary',
'_template_buttons_0_tb_color' => 'field_637e1750ba383',
'template_buttons_0_tb_icon' => '',
'_template_buttons_0_tb_icon' => 'field_637e18cfba384',
'template_buttons' => 1,
'_template_buttons' => 'field_637e171dba381',
]
)),
I am a skilled developer.. There is no information online that explains how to pre-populate repeater fields in a Innerblock template.
There are some tutorials/information about pre-population fields in a Innerblock template but nothing about repeater fields.
So thanks for your offer but I’m searching for a simple push in the right direction. And i’m pretty close with the array stacking in my last code snippet.
Yes thats why I made two query clauses in the first place…
So what I want is impossible. The date field will always be empty if the user chooses to set the Conditional field to “no date”.
Possible solution:
Then I have to make a function that triggers on post save that will fill the date field with dummy data so its filled?
So something like: (not correct code i know)
onpost save{
if(!get_field('activi_datumperiode')){ set activi_datum = 1}
}
Sorry for the long wait.. tried this code but doesnt work correctly.
The “activi_datum” is empty for the post that doesnt have “activi_datumperiode” enabled. Its a conditional field.
If “activi_datumperiode” turned on == enable “activi_datum” field.
If “activi_datumperiode” turned off == enable “free text” field.
What your code outputs is an ASC date list without the posts without a date.
Simply changing the relation “AND” in “OR” fixes the issue only orderby Date doenst work anymore.
22-03-2023
22-02-2023
28-03-2023
28-06-2023
11-05-2023
Every monday
Every Sunday
Looks like it orders by “activi_datumperiode” and then by post creation date
Thanks I think I allready tried this but without the compare “exists”.
I’m abroad right now, will try it out next week. Thank you for your help! 🙂
Got it! need to foreach the $filter array 🙁
if($programCat){
// meta filter
$metaFilter = array('relation' => 'OR');
foreach ($programCat as $program){
$filter = array(
'key' => 'zorgverlener_programmas',
'value' => '"'.$program.'"',
'compare' => 'LIKE'
);
array_push($metaFilter, $filter);
}
}
is there a nicer way to do this?
Some code:
acf_register_block_type(array(
'name' => 'tf-form',
'title' => 'Formulier',
'description' => 'Formulier toevoegen',
'render_template' => 'inc/blocks/tf-form/tf-form.php',
//'enqueue_style' => get_template_directory_uri() . '/template-parts/blocks/testimonial/testimonial.css',
//'enqueue_script' => get_template_directory_uri() . '/template-parts/blocks/testimonial/testimonial.js',
'category' => 'tatof',
'keywords' => '',
'className' => 'tf-form',
'icon' => array(
//'background' => '#7e70af',
//'foreground' => '#fff',
'src' => 'feedback',
),
'mode' => 'preview',
'align' => 'full',
'supports' => array(
'align' => false,
'align_text' => false, // $block['align_text']
'align_content' => false, // $block['align_content']
'mode' => true,
'multiple' => true,
'jsx' => false,
'color' => [
'gradients' => false
],
)
));
<?php
$blockname = 'tf-form';
// Create id
$id = $blockname.'-'.$block['id'];
if( !empty($block['anchor']) ) {
$id = $block['anchor'];
}
// Create class
$className = $blockname;
if( !empty($block['className']) ) {
$className .= ' ' . $block['className'];
}
if( !empty($block['align']) ) {
$className .= ' align' . $block['align'];
}
// Get custom color function
$block_color_attrs = get_block_color_attrs( $block );
// Load values and assing defaults.
$theform = get_field('block_form_form');
?>
<div id="<?php echo esc_attr($id); ?>" class="block100 <?php echo esc_attr($className); echo esc_attr( $block_color_attrs['class'] ); ?>">
<div class="innerblocks">
<?php
global $allowed_blocks;
echo '<InnerBlocks allowedBlocks="' . esc_attr( wp_json_encode( $allowed_blocks ) ) . '" />';
?>
</div>
<?php if ($theform){
echo do_shortcode('[gravityform id="'.$theform.'" title="false" description="false" ajax="true" tabindex="0"]');
} ?>
<div class="clearboth"></div>
</div>
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.