可能是因为catch_that_image()
正在接收全局$post_id
与相同the_post_thumbnail()
在代码中,可以传递当前章节的idcatch_that_image($chapter->ID)
或the_post_thumbnail( $chapter->ID )
这应该可以解决您的问题,或者您可以尝试此代码,它应该可以工作。
<?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="<?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;
?>
这里发生的事情是,我只是将您的代码分隔开来,使其更具可读性,在foreach循环中,我使用了
setup_postdata()
它用于设置全局post数据,通过它,您可以使用模板标记,而无需传递函数的ID,您可以使用
get_the_permalink()
而不是
get_the_permalink($chapter->ID)
在
foreach
循环I刚才使用此页面的原始post数据“清理”了post数据
wp_reset_postdata()