Home Forums General Issues setup_postdata not resetting with wp_reset_postdata()


setup_postdata not resetting with wp_reset_postdata()

  • So i’m using the relationship field to show some posts. The following works on my local install:

    $posts = get_field('journal_post');
    if( $posts ): ?>
      <p class="text-divider margin-b50 medium-10 medium-centered columns"><span class="walsheim">From our journals</p>
      <div class="posts heightfix margin-b50 medium-10 medium-centered columns">
      <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
          $link_text = get_field('link_text');
          $thumbnail = get_field('post_thumbnail')['sizes']['medium'];
          <figure class="journal-post text-center medium-4 columns">
            <a href="<?php echo get_the_permalink(); ?>">
              <img src="<?php echo $thumbnail; ?>">
              <figcaption class="text-14">
                <div class="category"><span>–</span> <?php echo the_category(); ?> <span>–</span></div>
                <p class="walsheim text-19 allcaps"><?php echo the_title(); ?></p>
                <?php echo the_excerpt(); ?>
                <!-- Post link -->
                <a class="chronicle" href="<?php echo get_the_permalink(); ?>"><?php echo $link_text ?></a>
      <?php endforeach; ?>
      <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>

    When I push this to my dev server, it seems as if the data is not resetting(as everything after the posts does not load, everything before does).

    Could anyone please help me with this? I’ve tried numerous options, but can’t seem to make it work properly. Thanks.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘setup_postdata not resetting with wp_reset_postdata()’ is closed to new replies.