I’m working on a WordPress site which has 2 blocks with post teasers from 2 different categories. One block (cat = 8) displays well, but the other one displays incorrect featured images.
Here is the code of the page containing the 2 blocks. I have 2 more separate pagina for displaying the posts but the problem is the same there.
<div style="margin: 0; width: auto;">
<h4 style="border-bottom: 1px solid #444;">Nieuws</h4>
<span class="more-news">
<a href="nieuws">meer nieuwsberichten</a>
</span>
<?php $the_query = new WP_Query( array('showposts' => '2', 'cat' => '9') ); ?>
<?php while ($the_query -> have_posts()) : ?>
<div class="unit-100 group teaser">
<?php if(has_post_thumbnail()){
$id = $the_query->post->ID;
echo get_the_post_thumbnail($id,array(100,100));
$the_query -> the_post(); ?>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<?php the_excerpt(__('(lees meerâ¦)'));
} else {
$the_query -> the_post(); ?>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<?php the_excerpt(__('(lees meerâ¦)'));
} ?>
</div>
<?php endwhile;
wp_reset_postdata();?>
</div>
</div>
<div class="unit-40">
<div class="donate">
<h4 style="border-bottom: 1px solid #444;">Doneer nu!</h4><?php echo do_shortcode('[IDEAL fip_referentie="The Blue Goat Donatie"]'); ?>
</div>
<div class="stories">
<h4 style="border-bottom: 1px solid #444;">Bijzondere verhalen uit Oeganda</h4>
<p><?php echo do_shortcode('[contentblock id=bijzondere-verhalen]'); ?></p>
<?php $the_query2 = new WP_Query( array('showposts' => '1', 'cat' => '8') ); ?>
<div class="">
<?php while ($the_query2 -> have_posts()) :
if(has_post_thumbnail()){
the_post_thumbnail(array(350,350));
$the_query2 -> the_post(); ?>
<span class="story-title"><a href="<?php the_permalink() ?>"><?php
the_title(); ?></a></span>
<?php } else {
$the_query2 -> the_post(); ?>
<a href="<?php the_permalink() ?>">Lees meer....</a>
<?php }
endwhile;
wp_reset_postdata(); ?>
</div>
</div>
1.) Make sure your pulling in correct Category ID. Check within WP dashboard and code.
2.) Maybe something like this: (anymore code related to this, we can see? Perhaps in functions.php?)