2017-05-30 80 views
0

我有一個顯示最新帖子的頁面,但我試圖排除某些類別的帖子。這是我的代碼:排除了wordpress上發佈的某些類別

<?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

WordPress不知道您試圖排除類別,排除參數是針對帖子ID。

從查詢中排除類別。您使用減號 '貓' 參數即'貓'=> ' - 8'

排除文章屬於類別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