我有一个显示最新帖子的页面,但我试图排除某些类别的帖子。这是我的代码:
<?php $categories = get_categories( $args ); ?>
<?php
$args = array( 'numberposts' => 2,
'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date", 'exclude'=>"8");
$postslist = get_posts( $args );
echo '<div class="latest_new_posts">';
foreach ($postslist as $post) : setup_postdata($post); ?>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12" >
<div class="blog-date-news"><span><?php the_date('d/m/Y'); ?></span></div>
<div class="blog-container">
<div class="news-blog-title"><span><?php the_title(); ?></span></div>
<div class="news-blog-excerpt"> <?php echo excerpt(500); ?> </div>
</div>
</div>
<?php endforeach; ?>
所以我试图从中排除类别ID 8,但它仍在显示。 我有什么想法我做错了吗?
答案 0 :(得分:0)
WordPress不知道您正在尝试排除类别,排除参数是针对帖子ID。
从“查询”中排除类别。你用'猫'#39;具有减号的参数,即&#39; cat&#39; =&gt;&#39; -8&#39;
排除属于类别ID 8的帖子
$args = array( 'numberposts' => 2,
'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date", 'cat'=>'-8');
来源: https://codex.wordpress.org/Class_Reference/WP_Query#Parameters