如何过滤帖子的类别

时间:2013-01-15 作者:Baig

有没有办法过滤帖子的类别?我正在使用wp_get_post_categories( $post -> ID );我想筛选此列表,即。if(post_name or post_id == "some id or some name") {it should not be displayed}

2 个回复
最合适的回答,由SO网友:Reigel 整理而成

你有没有试过,

$post_categories = wp_get_post_categories( $post -> ID  );

foreach($post_categories as $c){
    $cat = get_category( $c );
    if ( $cat->slug != "cat" ) {
       echo "$cat->name";
    };
}

SO网友:Mike Madern

您可以使用in_category():

$post_categories = wp_get_post_categories( $post->ID );

foreach( $post_categories as $cat_id ) {
    if ( in_category( $cat_id, POST_ID ) ) {
        // it should not be displayed
    } else {
        // it should be displayed
    }
}
在哪里POST_ID 应该是要检查的邮件的ID。

结束

相关推荐

Why posts array is empty?

我尝试获取没有自定义字段集的帖子,或者if set的值与给定的参数不同。这是我的代码: $args_included = array( \'numberposts\' => 1, \'post_type\' => \'post\', \'post_status\' => \'published\', \'meta_query\' => array(&#x