我有一个名为“视频”的自定义帖子类型,我正在使用高级自定义字段插件和一个选择字段作为过滤器,以指定帖子部分在我的页面上的显示位置。我有两个栏目,一个叫做“我们的工作”,另一个叫做“特色电影”。我需要每个栏目显示最新的4篇文章,但当我更改每页的posts\u时,它会影响总数,是否有办法将其限制为每个查询仅4篇?子问题相同的查询可以运行两次吗?我的代码是:
<div class="triple ourWork col-sm-6">
<h2>Our Work</h2>
<?php $loop = new WP_Query( array( 'post_type' => 'videos', 'posts_per_page'
=> 4) ) ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php if( get_field('labeled_as') == 'our work' ): ?>
<div class="col-sm-6" id="">
<?php global $post;
$gethref = $post->post_name;
?>
<div class="holder" style="background-image: linear-gradient(0deg,rgb(38, 38, 42, .5),rgb(38, 38, 42, .5)), url(<?php echo the_field('screenshot'); ?>);"><a href="/<?php echo $gethref ?>"><span class="play"><?php the_title(); ?></span></a></div>
<p><?php echo the_field('issue_short_description'); ?></p>
</div>
<?php endif; ?>
<?php endwhile; ?>
</div>
<div class="triple featuredFilms col-sm-6">
<h2>Featured Films</h2>
<?php $loop = new WP_Query( array( 'post_type' => 'videos', 'posts_per_page' => 4 ) ) ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php if( get_field('labeled_as') == 'featured film' ): ?>
<div class="col-sm-6" id="">
<?php global $post;
$gethref = $post->post_name;
?>
<div class="holder" style="background-image: linear-gradient(0deg,rgb(38, 38, 42, .5),rgb(38, 38, 42, .5)), url(<?php echo the_field('screenshot'); ?>);"><a href="/<?php echo $gethref ?>"><span class="play"><?php the_title(); ?></span></a></div>
<p><?php echo the_field('issue_short_description'); ?></p>
</div>
<?php endif; ?>
<?php endwhile; ?>
</div>