0

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?

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.