I have created a custom block in WordPress, using an ACF registered block. The purpose of the block is to allow the addition of either a regular post, or a custom post type post to a page. The block works as expected with a regular post. However, no data created/saved through acf is showing up for any of the custom post types. The title and permalink values are there, so I know the post has been located, but for some reason none of the custom field data is coming through. These same content loops work as expected when not used in a block context (e.g. directly in a page template).
this is the block's render.php:
$theme = get_stylesheet_directory();
$loop_templates = $theme . '/loop-templates/';
$post_type = get_field('post_type');
switch ($post_type) {
case 'Podcast':
$cpt = 'podcasts';
break;
case 'Newsletter':
$cpt = 'newsletters';
break;
case 'Blog Post':
$cpt = 'post';
break;
case 'Download':
$cpt = 'downloads';
break;
case 'Video':
$cpt = 'videos';
break;
default:
$cpt = 'post';
}
$choose_post = get_field('choose_post');
if($choose_post == 'most recent'){
$post = new WP_Query( array(
'post_type' => $cpt,
'posts_per_page' => 1
) );
if ( $post->have_posts() ) :
while ( $post->have_posts() ) : $post->the_post();
if($post_type == 'Podcast'):
include($loop_templates.'content-podcast.php');
elseif($post_type == 'Newsletter'):
include($loop_templates.'content-newsletter.php');
elseif($post_type == 'Blog Post'):
include($loop_templates.'content-post.php');
elseif($post_type == 'Download'):
include($loop_templates.'content-download.php');
elseif($post_type == 'Video'):
include($loop_templates.'content-video.php');
endif;
wp_reset_postdata();
endwhile;
endif;
wp_reset_query();
}
_______________________________________
And this is an example of the custom post type loop template:
_______________________________________
$rn_title = get_the_title( $post->ID );
$rn_date = get_field('rn_date', $post -> ID);
$rn_link = get_permalink($post -> ID);
$rn_introduction= get_field('rn_introduction' , $post -> ID);
$rn_excerpt = limit_text($rn_introduction, 70);
$rn_banner = get_field('rn_banner', $post -> ID);
$rn_thumbnail_image = get_field('rn_thumbnail_image', $post -> ID);
$rn_size = array('506', '169');
var_dump($rn_thumbnail_image);
$newsletter_html = '<div class="card">';
$newsletter_html .= '<a href="' . $rn_link . '">';
if($rn_thumbnail_image ):
$newsletter_html .= 'hiya';
$newsletter_html .= '<img src="' . $rn_thumbnail_image . '" alt="' . $rn_title . '">';
elseif($rn_banner):
$newsletter_html .= wp_get_attachment_image($rn_banner, $rn_size );
endif;
$newsletter_html .= '<div class="card-body">';
$newsletter_html .= '<h5 class="card-title">' . $rn_title . '</h5>';
$newsletter_html.= '<div class="card-label">NEWSLETTER</div>';
$newsletter_html .= '<p class="card-text">';
$newsletter_html .= '<div class="card-date date">' . $rn_date . '</div>';
$newsletter_html .= '<div class="card-excerpt">' . $rn_excerpt . '</div>';
$newsletter_html .= '</p>';
$newsletter_html .= '</div></a><!-- .card-body -->';
$newsletter_html .= '</div><!-- .card -->';
?>
<article <?php post_class();?> id="post-<?php the_ID();?>">
<div class="entry-content">
<?php echo $newsletter_html ?>
</div><!-- .entry-content -->
</article><!-- #post-## -->