Hey Guys,
This is possible already.
Here is the post about it:
https://support.advancedcustomfields.com/forums/topic/programmatically-set-blocks-initial-value/
And the code which helps you to make better experiences! : )
The magic is that, you need to wrap them with a data []
'template' => [
['acf/my-block', [
'data' => [
'field_name' => 'the value you want to see by default',
]
]]
];
I hope it helps you too as well!
I’m stuck with repeater subfields now.
Didn’t find a way to fill them yet.
If any of you able to do that, don’t hesitate to write here about that. 😉
Bests,
Christian
Hey @anybodesign
You should able to do that via get_posts() too.
The most problem you don’t use the proper order value for that.
I think you want to change the ‘order’ like this:
$posts = get_posts([
'post_type' => 'product',
...
'meta_key' => 'your_date_field',
'orderby' => 'meta_value_num',
]);
The key is the meta_value_num when you order by number / date type of fields
Hey @webbmaster ,
You should unwrap the field from <p> tags, so let it:
<?php
echo $background['del1'];
?>
Hey @panayotoff ,
Thank you for your share, it helped me a lot!
Did you able to fill up repeater type of fields too?
It seems not to work for me with those type of fields.
Hey @varilux2k ,
It seems you’re using JavaScript ( JQuery > $ ) within PHP tags wrongly.
PHP solution:
<?php
if (!wp_is_mobile()) {
echo $slider_image['url'];
} else {
echo $slider_image_mobile ['url'];
}
?>
HTML solution:
<picture>
<source media="(min-width: 36em)"
srcset="large.jpg 1024w,
medium.jpg 640w,
small.jpg 320w"
sizes="33.3vw" />
<source srcset="cropped-large.jpg 2x,
cropped-small.jpg 1x" />
<img src="small.jpg" alt="A rad wolf" />
</picture>
JavaScript solution ( if you extend your html with data attr ):
<script>
var imageBgs = document.querySelectorAll('[data-bg-mobile]');
var screenWidth = window.innerWidth;
for(var i=0; i<imageBgs.length; i++) {
if( screenWidth < 576 ){
// Load mobile image
imageBgs[i].style.backgroundImage = 'url('+imageBgs[i].getAttribute('data-bg-mobile')+')';
}
}
</script>
Yes, you could this by target the proper field type:
// ACF > WYSIWYG — Custom Toolbar
add_filter( 'acf/fields/wysiwyg/toolbars', function ( $toolbars ) {
// Unset Basic Type Toolbar
unset( $toolbars['Basic'] );
// [1] formatselect. bold, italic, bullist, numlist, blockquote, alignleft, aligncenter, alignright, link, wp_more, spellchecker, fullscreen, wp_adv
// [2] strikethrough, hr, forecolor, pastetext, removeformat, charmap, outdent, indent, undo, redo, wp_help
// Register a basic toolbar with a single row of options
$toolbars['Full'][1] = [
'formatselect',
'fontsizeselect',
'bold',
'italic',
'alignleft',
'aligncenter',
'alignright',
'bullist',
'numlist',
'link',
'unlink',
'forecolor',
'hr',
'removeformat'
];
$toolbars['Full'][2] = [];
return $toolbars;
});
+1
It’d saves plenty of times, and give us the real power to use acf blocks as template
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.