当我想排除某些帖子时,wp-query 'post__not_in' 不起作用



这是我的代码,我正在尝试排除一些已经添加到自定义帖子类型中的帖子,但它对我不起作用,如果有人能帮我吗??

<div class="grid-x small-up-1 medium-up-3 large-up-3 gridi">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php 
$args = array(
'post_type' => 'gallery',
'posts_per_page' => -1,
'post__not_in' => array (779, 1394, 774, 3278),
);
$loop = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="cell">
<div class="item-navigation">
<a href="<?php the_permalink(); ?>">
<div class="image-container">
<?php the_post_thumbnail(); ?>
<div class="description">
<h5 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
<p><?php the_excerpt(); ?></p>
<a class="read-more" href="<?php the_permalink(); ?>">Read More</a>
</div>
</div>
</a>
</div>
</div>
<?php endwhile; endif; ?>
</div>

此行..:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

只需执行全局wpquery。没有使用您将上面的行声明为$loop的查询。

尝试:

<?php if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); ?>

最新更新