0

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_rreturns the correct values.

Any idea ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.