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)

The topic ‘Post Object in Gutenberg doesn\'t show content’ is closed to new replies.