Hello! I’m having the following problem. Right now lets say i have “Products” custom post type, and “Recipes” custom post type. In a single recipe post, i want to include the ingredients (products) that i used for the recipe. In advanced custom fields i’ve added a Relationship Field for Recipes, to choose posts from Products. I named the field “products_of_recipe”. I chose some products and now i want to display them inside the single recipe post. I’ve added the following code which i read in the documentation but it doesn’t work. What am i doing wrong?
$posts = get_field('products_of_recipe');
if( $posts ): ?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<div class="col-2 no-margin-left-wbottom">
<img src="<?php the_field('single_product_thumb'); ?>">
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users