Ok, ok, in classic form you know how after a couple of hours of banging your head and then posting in support as a final cry for help you stumble across the obvious answer.
Well, here it is in case anyone else is lost.
You need to make sure “SUB” is added to the code like so:
<?php if( get_sub_field('file') ): ?>
<a href="<?php the_sub_field('file'); ?>" >Download File</a>
<?php endif; ?>
So add “get_sub_field” and “the_sub_field” and it will work. You need to add “sub” for repeaters and adjust the code inside accordingly.
Ok, this is a little embarrassing but I found the issue. The carousel block settings in Advanced Custom Fields was set to “Show this Field Group if > Block > Is equal to > ALL” and that was the cause. I didn’t notice it before because that was the first block I created so it looks like after I created the other ones that one got set to “ALL” by default without me realizing it.
You can make your block default to edit mode by adding this:
'mode' => 'edit'
I also widen the entire editor blocks by throwing this in my functions.php
//------------------------------------------------
// Admin CSS
//------------------------------------------------
add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
echo
'<style>
.wp-block {max-width: 1200px;}
</style>';
}
This is an alternative, it does the same thing as the other version I posted but when I create a Card block, I’m still getting the Carousel block appearing below the Card block in the editor, they appear together as if they were all one block
However, if I add the Carousel block, it is just the Carousel which is expected. I have scoured the Internet and have yet to find out how to create multiple ACF blocks.
Seems like you’d just register a new block and it should work but I’m having issues when adding the Card block and it including the Carousel block along with it.
add_action('acf/init', 'my_acf_blocks_init');
function my_acf_blocks_init() {
// Check function exists.
if( function_exists('acf_register_block_type') ) {
// register a Carousel block
acf_register_block_type(array(
'name' => 'carousel',
'title' => __('Carousel'),
'description' => __('Show images in a carousel'),
'render_template' => 'blocks/carousel.php',
'category' => 'common',
'icon' => 'slides',
'keywords' => array( 'carousel', 'gallery' ),
'mode' => 'edit'
));
// register a Card block
acf_register_block_type(array(
'name' => 'card',
'title' => __('Card'),
'description' => __('Card with photo and info'),
'render_template' => 'blocks/card.php',
'category' => 'common',
'icon' => 'id',
'keywords' => array( 'card', 'team' ),
'mode' => 'edit'
));
}
}
function register_acf_block_types() {
// register a Carousel block
acf_register_block_type(array(
'name' => 'carousel',
'title' => __('Carousel'),
'description' => __('Show images in a carousel'),
'render_template' => 'blocks/carousel.php',
'category' => 'common',
'icon' => 'slides',
'keywords' => array( 'carousel', 'gallery' ),
'mode' => 'edit'
));
// register a Card block
acf_register_block_type(array(
'name' => 'card',
'title' => __('Card'),
'description' => __('Card with photo and info'),
'render_template' => 'blocks/card.php',
'category' => 'common',
'icon' => 'id',
'keywords' => array( 'card', 'team' ),
'mode' => 'edit'
));
}
// Check if function exists and hook into setup.
if( function_exists('acf_register_block_type') ) {
add_action('acf/init', 'register_acf_block_types');
}
I tried the same thing. When I add the Carousel in the editor I get just the Carousel, but when I try to add the Card, it shows the Carousel and the Card in the same block which I don’t want.
Anyone else having this problem? What am I missing?
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.