【发布时间】:2026-01-29 09:15:01
【问题描述】:
我试图从自定义帖子类型循环中排除一个类别,但没有运气。我不知道为什么这不起作用。我查遍了整个互联网,但没有运气,请有人帮忙找出问题所在。
我有一个 ID 为 141 的类别。
我正在运行一个帖子循环,我试图排除分配给该类别的帖子,但它们仍然显示在循环中。我哪里错了?这是我的代码。
<?php
$args = array(
'post_type' => 'programme',
'cat' => -141,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<div class="grid-item">
<?php the_title(); ?>
</div>
<?php
endwhile;
else:
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
wp_reset_postdata();
?>
【问题讨论】:
-
在您的
$args中更改'cat' => '-141',而不是'cat' => -141,
标签: php wordpress custom-post-type custom-taxonomy