Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading