Hello,
I build a “Featured Product” Gutenberg block where i can choose a product (custom post type) or more via Relationship Field. This is working fine and Thumbnail, Title, Permalink etc are shown properly.
But, I can’t call the custom fields which are stored inside the featured product itself. There I have Fields like Price, Link, Shop etc. They are wrapped up in a group. But I can’t call them, they are not shown on the frontend. Anyone knows a solution?
Here is my Code of the Block Render Template.
<?php
global $post;
$posts = get_field('block_products');
if( $posts ): ?>
<?php foreach( $posts as $post): ?>
<?php setup_postdata($post); ?>
<div class="box-product">
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<div class="image">
<?php the_post_thumbnail('thumb-square-m'); ?>
</div>
</a>
<?php endif; ?>
<div class="copy">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<span class="headline name"><?php the_title(); ?></span>
</a>
<?php
$singleproduct = get_field('products');
if( $singleproduct ): ?>
<div class="productbox">
<div class="headline price">
<?php echo $singleproduct['price']; ?>
</div>
<div class="cta">
<a class="button buy" href="<?php echo $singleproduct['link']; ?>" target="_blank" rel="nofollow">Jetzt bei <?php echo $singleproduct['shop']; ?> kaufen</a>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
Ok, my fault. The solution is:
<?php
$singleproduct = get_field('products', $post->ID);
if( $singleproduct ):
?>