Home > OS >  How to Display Post Content in an Accordion Using Gutenberg ACF
How to Display Post Content in an Accordion Using Gutenberg ACF

Time:01-26

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 >
    <?php if (!empty($choose_acc_item)) : ?>
        <?php
        foreach ($choose_acc_item as $item) : ?>
            <div >
                <button ><?php echo $item->post_title; ?>
                </button>
                <div >
                    <?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

CodePudding user response:

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 >
    <?php if (!empty($choose_acc_item)) : ?>
        <?php
        foreach ($choose_acc_item as $item) : ?>
            <div >
                <button ><?php echo $item->post_title; ?>
                </button>
                <div >
                    <?php echo apply_filters('the_content', $item->post_content); ?>
                </div>
            </div>
    <?php
        endforeach;
    endif; ?>

</div>
  • Related