从帖子中排除某些类别

时间:2017-05-30 作者:tasmanianDevil123

我有一个显示最新帖子的页面,但我试图从某些类别中排除帖子。这是我的代码:

<?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,但它仍在显示。知道我做错了什么吗?

1 个回复
SO网友:Rarst

exclude 在里面get_posts() 指的是post ID,它们不能与类别ID互换。

你要找的论点可能是\'category__not_in\' => [ 8 ]

结束