Issue with ACF and setup_postdata
Question
On my single post template, I hook a partial template using the following code in order to display related products above the post content :
<?php if ( have_rows( 'featured_products' ) ) : ?>
<?php while ( have_rows( 'featured_products' ) ) :
the_row(); ?>
<?php if ( $headline = get_sub_field( 'headline' ) ) : ?>
<?php echo esc_html( $headline ); ?>
<?php endif; ?>
<?php
$product = get_sub_field( 'product' );
if ( $product ) :
$post = $product;
setup_postdata( $post );
print_r($post);
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
The headline
value is returned correctly. However, when it comes to product
, it returns values of the current post (and not the related post). As you can see setup_postdata
is here, so I don’t really understand… In addition print_r
returns the correct values.
Any idea ?
0
advanced-custom-fields, loop, theme-development
7 months
0 Answers
102 views
0
Leave an answer
You must login or register to add a new answer .