Home Forums Gutenberg Include ACF Block from code


Include ACF Block from code

  • I was wondering if it is possible to reuse the acf block templates from code.

    – I have registered a block called ‘related posts’.
    – I can add this block in the Gutenberg editor and fill the fields
    – block_header (text)
    – amount_of_posts_to_show (number)

    Gutenberg now renders my block using my php template I registered and this is all working fine.

    But what I want is to add one of these blocks to my post-template (not block-template) via code

    e.g. something like this:

    <?php get_header(); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h1><?php the_title(); ?></h1>
    <div><?php the_content(); ?></div>
    'blockType' => 'acf/my-block',
    'block_header' => 'This is a header',
    'amount_of_posts_to_show' => 3
    <?php wp_reset_postdata(); ?>
    <?php endwhile; endif; ?>
    <?php get_footer(); ?> 

    On some pages the content writer might want some freedom regarding where this block should be placed, but on many pages I want this block to be placed by default, without the writer having to manually place them each time.

    Can this be done?

  • Hi,
    did you found a solution for this problem?
    Best regards,

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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.