Search code examples
phpwordpressadvanced-custom-fieldswordpress-gutenberg

How to Display Post Content in an Accordion Using Gutenberg+ ACF


I have an accordion which is inserted as a Post Object ACF. Each accordion item is a post. I have separate ACF + Gutenberg content blocks that I insert into a post. Now the problem is that when opening the accordion, it is empty and does not see the content block. How can I display Gutenberg blocks inside a post?

<div class="accordion-block">
    <?php if (!empty($choose_acc_item)) : ?>
        <?php
        foreach ($choose_acc_item as $item) : ?>
            <div class="accordion-block__item">
                <button class="accordion-item__title"><?php echo $item->post_title; ?>
                </button>
                <div class="accordion-item__content">
                    <?php echo $item->post_content; ?>
                </div>
            </div>
    <?php
        endforeach;
    endif; ?>

</div>

In the code inspector:

Output value

There should be a video, the block of which I made with ACF + Gutenberg


Solution

  • you need to use the apply_filters() function on the content to run all of the content hooks. this should make the video display although the code is untested.

    <div class="accordion-block">
        <?php if (!empty($choose_acc_item)) : ?>
            <?php
            foreach ($choose_acc_item as $item) : ?>
                <div class="accordion-block__item">
                    <button class="accordion-item__title"><?php echo $item->post_title; ?>
                    </button>
                    <div class="accordion-item__content">
                        <?php echo apply_filters('the_content', $item->post_content); ?>
                    </div>
                </div>
        <?php
            endforeach;
        endif; ?>
    
    </div>