我已经设置了一个自定义字段来提取指定的类别ID,以便在页面侧栏上使用WP_Query来显示。它会将帖子拉入正确的类别,但会跳过最新的帖子。以下是代码片段:
<?php
$catID = get_field ( 'category_id_posts' );
$catquery = new WP_Query( 'cat='. $catID .'&posts_per_page=5' );
?>
<?php if($catquery->have_posts()) : $catquery->the_post(); ?>
<div id="recent-posts-2">
<h3 class="widget-title">Recent Posts</h3>
<ul class="nav flex-column">
<?php while($catquery->have_posts()) : $catquery->the_post(); ?>
<li class="nav-item">
<a class="nav-link" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php
endif;
wp_reset_postdata(); ?>
即使我简化了WP_Query并像这样删除变量:
$catquery = new WP_Query( 'cat=7&posts_per_page=5' );
它仍然会跳过该类别中的最新帖子。
任何见解将不胜感激,谢谢!
慕码人8056858
倚天杖