ACF to select posts not displaying on blog page

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?

Topic advanced-custom-fields loop posts Wordpress

Category Web


a global $post; before your loops might do the job

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.