It”s probably because catch_that_image()
is receiving the global $post_id
the same with the_post_thumbnail()
in your code you could pass the id of your current chapter catch_that_image($chapter->ID)
or the_post_thumbnail( $chapter->ID )
this should solve your problem or you can try this code, it should work.
<?php
global $post;
$current_post = get_the_ID();
$FeaturedArtist = get_post_meta($current_post, 'FeaturedArtist', true);
if($FeaturedArtist):
$chapters_args = array(
'posts_per_page' => -1,
'meta_key' => 'FeaturedArtist',
'meta_value' => $FeaturedArtist,
'orderby' => 'date',
'post__not_in' => array( $current_post )
);
$chapters = get_posts( $chapters_args );
foreach( $chapters as $post ):
setup_postdata( $post );
?>
<div class="box more">
<a href="https://wordpress.stackexchange.com/questions/167443/<?php echo esc_url( get_permalink() ); ?>" alt="CONTEST ENTRY by <?php echo esc_attr( get_the_title() ); ?>" title="CONTEST ENTRY by <?php echo esc_attr(get_the_title()); ?> ">
<img src="<?php echo catch_that_image() ?>" width="625px" alt="<?php echo esc_attr( get_the_title()); ?>"/>
<div class="articleTitle">
<span class="titleType">CONTEST ENTRY<br /><span class="titleArticle"><?php the_title(); ?></span></span>
</div>
</a>
</div>
<?php
endforeach;
wp_reset_postdata();
endif;
?>
What happens here is I just separeted your code to be a little bit more readable and in the foreach loop I’ve used the setup_postdata()
that is used to set the global post data and with this you can use the template tags without having to pass the ID for the functions, you can use get_the_permalink()
instead of get_the_permalink($chapter->ID)
and after the foreach
loop I just “cleaned” the post data with the original post data for this page using wp_reset_postdata()