Support

Account

Home Forums Gutenberg Post Object in Gutenberg doesn\'t show content

Unread

Post Object in Gutenberg doesn\'t show content

  • Hi. I am trying to create a Gutenberg block with ACF. The block contains a post object field. The content of the post (selected in post object field) is shown in the front end, but not in the back end in the gutenberg preview.

    Is there a workaround for this?
    What do I have to consider?

    Here is my code for the block.

    
    <?php if( have_rows('cta_content') ): ?>
    	<?php while( have_rows('cta_content') ): the_row(); ?>
    		<?php if( get_row_layout() == 'individually' ): ?>
    			<h1 class="cta__headline"><?php the_sub_field('headline'); ?></h1>
    			<div class="cta__content"><?php the_sub_field('content'); ?></div>
    		<?php elseif( get_row_layout() == 'from_post' ): ?>
    			
    			<?php
    			
    			$post_object = get_sub_field('content');
    			
    			if( $post_object ):
    				
    				// override $post
    				$post = $post_object;
    				setup_postdata( $post );
    				
    				?>
    				<div>
    					<h1 class="cta__headline"><?php the_title(); ?></h1>
    					<div class="cta__content"><?php the_content(); ?></div>
    				</div>
    				<?php wp_reset_postdata(); ?>
    			<?php endif; ?>
    		
    		<?php endif; ?>
    	<?php endwhile; ?>
    <?php endif; ?>
    
Viewing 1 post (of 1 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.