有没有办法过滤帖子的类别?我正在使用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。结束