0

Took over a project, and one of the errors is the featured images (and certain others rendered in a similar way) are duplicating themselves and replacing the next image thumbnail.

      <a href="<?php echo get_permalink(); ?>" class="snack__thumb snack__thumb--featured" style="background-image:url('<?php echo get_the_post_thumbnail_url( $post->ID, 'medium' ); ?>');">
<?php
  if (has_category('whitepaper')) { ?>
    <div class="snack__banner"><span>whitepaper</span></div>
  <?php 
  } 
?>

I've read that not ending a loop with something like wp_reset_postdata(); can cause this type of error however I haven't been able to get it solved.

Relevant plugins installed are
NS Featured Posts Ajax-Load-More (Error happening within Load-more field)

This happens on the home page as well in this loop

<?php while ($latest_posts->have_posts()) : ?>
  <div class="col-md-4">
    ?php 
      $latest_posts->the_post();
      include(locate_template('loop-templates/content-snack.php'));
    ?>
  </div>
  <?php endwhile; wp_reset_query(); ?>
  </div>
  <?php 
    if ($latest_posts->max_num_pages > 1) {
      echo(do_shortcode('[ajax_load_more id="posts-loader" container_type="div" post_type="post" posts_per_page="6" post_format="standard" pause="true" post__not_in="'.implode(",",$special_ids).'" scroll="false" transition_container_classes="row" button_label="See more posts"]'));
    }
  ?>

2
  • Hey Ranson Namba, can you include a more complete snippet of code. Your current code doesn't really tell us anything. If the issue is with your main loop show us that. If it's a custom loop, show that. And can you give more context around your issue? Is this a single post? An archive? Is javascript or the load more plugin causing this? Have you tried deactivating that plugin? Or turning javascript off? – ngearing Jul 5 '19 at 0:49
  • Updated with more code. I don't believe that a custom loop has been created. This is mainly in a plugin ajax-load-more, the developer said that it can be an error in the repeater template, or queries higher up not being reset with wp_reset_query() – Ranson Namba Jul 5 '19 at 2:04
0

This was due to having an inline <?php $post = get_post()?> After moving this out and making it global, images stopped duplicating.

Your Answer

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

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