这里发生的是你正在设置$landscape
在循环之前,因此只设置一次。(因此它会显示在循环中的每个项目中。)
要解决此问题,请移动第五行-$landscape
- 在回路内部。
<?php
$args = array( \'post_type\' => \'products\', \'posts_per_page\' => 9 );
$the_query = new WP_Query( $args );
// No longer setting $landscape here, which only sets it once.
?>
<main class="site-content">
<div class="row">
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
// Landscape now pulls for the current post.
$landscape = get_field(\'main_photo_landscape\', $post->ID);
?>
<article class="col-12 col-md-6 col-lg-4 product">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<div class="featured-img" style="background: url(\'<?php echo $landscape[\'sizes\'][\'large\']; ?>\') center center no-repeat; background-size: auto 100%"></div>
<h1 class="title"><?php the_title(); ?></h1>
<button class="btn">More Details</button>
</a>
</article>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php endif; ?>
</div>
</main>
这将为每个岗位拉取ACF字段。