I am trying to implement a repeater / post object so I can select posts that I want to displaying on the sidebar. I am using this code:
<?php while ( have_rows('top_posts_repeater')) : the_row(); // loop through the repeater fields ?>
<?php // set up post object
$post_object = get_sub_field('selection');
if( $post_object ) :
$post = $post_object;
setup_postdata($post);
?>
<article class="your-post">
<?php the_title(); ?>
<?php the_post_thumbnail(); ?>
<?php // whatever post stuff you want goes here ?>
</article>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
<?php endwhile; ?>
The code works if I insert it on any page but it doesn't work if I insert it in the blog page. What am I missing?